-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add - doc - Added vCard 4.0 RELATED and CLIENTPIDM...
...AP properties --- We've added two new properties to the vCard parser for vCard 4.0: CLIENTPIDMAP and RELATED. --- Type: add Breaking: False Doc Required: True Backport Required: False Part: 1/1
- Loading branch information
Showing
5 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// | ||
// VisualCard Copyright (C) 2021-2024 Aptivi | ||
// | ||
// This file is part of VisualCard | ||
// | ||
// VisualCard is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// VisualCard is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using Textify.General; | ||
|
||
namespace VisualCard.Parts.Implementations | ||
{ | ||
/// <summary> | ||
/// Client PID map info | ||
/// </summary> | ||
[DebuggerDisplay("Client PID Map = {PidNum};{PidUri}")] | ||
public class ClientPidMapInfo : BaseCardPartInfo, IEquatable<ClientPidMapInfo> | ||
{ | ||
/// <summary> | ||
/// Client PID number | ||
/// </summary> | ||
public int PidNum { get; } | ||
|
||
/// <summary> | ||
/// Client PID URI | ||
/// </summary> | ||
public string? PidUri { get; } | ||
|
||
internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) => | ||
new ClientPidMapInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, group, valueType, cardVersion); | ||
|
||
internal override string ToStringVcardInternal(Version cardVersion) => | ||
$"{PidNum};{PidUri ?? ""}"; | ||
|
||
internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) | ||
{ | ||
// Split the client PID map info | ||
if (!value.Contains(";")) | ||
throw new InvalidDataException($"Client PID map representation is invalid: {value}"); | ||
|
||
// Parse the info | ||
string pidNumStr = value.Substring(0, value.IndexOf(";")); | ||
string pidUriStr = value.RemoveSuffix($"{pidNumStr};"); | ||
if (!int.TryParse(pidNumStr, out int pidNum)) | ||
throw new InvalidDataException($"PID number {pidNumStr} is invalid"); | ||
if (!Uri.TryCreate(pidUriStr, UriKind.Absolute, out Uri uri)) | ||
throw new InvalidDataException($"PID URI {pidUriStr} is invalid"); | ||
pidUriStr = uri.ToString(); | ||
|
||
// Populate the fields | ||
ClientPidMapInfo _source = new(altId, finalArgs, elementTypes, valueType, group, pidNum, pidUriStr); | ||
return _source; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool Equals(object obj) => | ||
Equals((ClientPidMapInfo)obj); | ||
|
||
/// <summary> | ||
/// Checks to see if both the parts are equal | ||
/// </summary> | ||
/// <param name="other">The target <see cref="ClientPidMapInfo"/> instance to check to see if they equal</param> | ||
/// <returns>True if all the part elements are equal. Otherwise, false.</returns> | ||
public bool Equals(ClientPidMapInfo other) => | ||
Equals(this, other); | ||
|
||
/// <summary> | ||
/// Checks to see if both the parts are equal | ||
/// </summary> | ||
/// <param name="source">The source <see cref="ClientPidMapInfo"/> instance to check to see if they equal</param> | ||
/// <param name="target">The target <see cref="ClientPidMapInfo"/> instance to check to see if they equal</param> | ||
/// <returns>True if all the part elements are equal. Otherwise, false.</returns> | ||
public bool Equals(ClientPidMapInfo source, ClientPidMapInfo target) | ||
{ | ||
// We can't perform this operation on null. | ||
if (source is null || target is null) | ||
return false; | ||
|
||
// Check all the properties | ||
return | ||
source.PidNum == target.PidNum && | ||
source.PidUri == target.PidUri | ||
; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() | ||
{ | ||
int hashCode = -659626044; | ||
hashCode = hashCode * -1521134295 + base.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + PidNum.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string?>.Default.GetHashCode(PidUri); | ||
return hashCode; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public static bool operator ==(ClientPidMapInfo left, ClientPidMapInfo right) => | ||
left.Equals(right); | ||
|
||
/// <inheritdoc/> | ||
public static bool operator !=(ClientPidMapInfo left, ClientPidMapInfo right) => | ||
!(left == right); | ||
|
||
internal override bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo target) => | ||
((ClientPidMapInfo)source) == ((ClientPidMapInfo)target); | ||
|
||
internal ClientPidMapInfo() { } | ||
|
||
internal ClientPidMapInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string group, int pidNum, string pidUri) : | ||
base(arguments, altId, elementTypes, valueType, group) | ||
{ | ||
PidNum = pidNum; | ||
PidUri = pidUri; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// | ||
// VisualCard Copyright (C) 2021-2024 Aptivi | ||
// | ||
// This file is part of VisualCard | ||
// | ||
// VisualCard is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// VisualCard is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY, without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
|
||
namespace VisualCard.Parts.Implementations | ||
{ | ||
/// <summary> | ||
/// Related URI info | ||
/// </summary> | ||
[DebuggerDisplay("Related URI = {Related}")] | ||
public class RelatedInfo : BaseCardPartInfo, IEquatable<RelatedInfo> | ||
{ | ||
/// <summary> | ||
/// Encoded related URI | ||
/// </summary> | ||
public string? RelatedUri { get; } | ||
|
||
internal static BaseCardPartInfo FromStringVcardStatic(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) => | ||
new RelatedInfo().FromStringVcardInternal(value, finalArgs, altId, elementTypes, group, valueType, cardVersion); | ||
|
||
internal override string ToStringVcardInternal(Version cardVersion) => | ||
RelatedUri ?? ""; | ||
|
||
internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string group, string valueType, Version cardVersion) | ||
{ | ||
// Try to parse the source to ensure that it conforms the IETF RFC 1738: Uniform Resource Locators | ||
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri)) | ||
throw new InvalidDataException($"source {value} is invalid"); | ||
value = uri.ToString(); | ||
|
||
// Populate the fields | ||
RelatedInfo _source = new(altId, finalArgs, elementTypes, valueType, group, value); | ||
return _source; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override bool Equals(object obj) => | ||
Equals((RelatedInfo)obj); | ||
|
||
/// <summary> | ||
/// Checks to see if both the parts are equal | ||
/// </summary> | ||
/// <param name="other">The target <see cref="RelatedInfo"/> instance to check to see if they equal</param> | ||
/// <returns>True if all the part elements are equal. Otherwise, false.</returns> | ||
public bool Equals(RelatedInfo other) => | ||
Equals(this, other); | ||
|
||
/// <summary> | ||
/// Checks to see if both the parts are equal | ||
/// </summary> | ||
/// <param name="source">The source <see cref="RelatedInfo"/> instance to check to see if they equal</param> | ||
/// <param name="target">The target <see cref="RelatedInfo"/> instance to check to see if they equal</param> | ||
/// <returns>True if all the part elements are equal. Otherwise, false.</returns> | ||
public bool Equals(RelatedInfo source, RelatedInfo target) | ||
{ | ||
// We can't perform this operation on null. | ||
if (source is null || target is null) | ||
return false; | ||
|
||
// Check all the properties | ||
return | ||
source.RelatedUri == target.RelatedUri | ||
; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override int GetHashCode() | ||
{ | ||
int hashCode = 881496785; | ||
hashCode = hashCode * -1521134295 + base.GetHashCode(); | ||
hashCode = hashCode * -1521134295 + EqualityComparer<string?>.Default.GetHashCode(RelatedUri); | ||
return hashCode; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public static bool operator ==(RelatedInfo left, RelatedInfo right) => | ||
left.Equals(right); | ||
|
||
/// <inheritdoc/> | ||
public static bool operator !=(RelatedInfo left, RelatedInfo right) => | ||
!(left == right); | ||
|
||
internal override bool EqualsInternal(BaseCardPartInfo source, BaseCardPartInfo target) => | ||
((RelatedInfo)source) == ((RelatedInfo)target); | ||
|
||
internal RelatedInfo() { } | ||
|
||
internal RelatedInfo(int altId, string[] arguments, string[] elementTypes, string valueType, string group, string source) : | ||
base(arguments, altId, elementTypes, valueType, group) | ||
{ | ||
RelatedUri = source; | ||
} | ||
} | ||
} |