Skip to content

Commit

Permalink
imp - Improved property folding
Browse files Browse the repository at this point in the history
---

We've improved the property folding mechanism to handle cases where we encounter a very long argument that can't be wrapped into 74 octets.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 2, 2024
1 parent f86e002 commit 9af466c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
16 changes: 8 additions & 8 deletions VisualCard/Parsers/VcardCommonTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -505,29 +505,29 @@ internal static string GetFirstValue(string[] args, string @default, string argS
return argString;
}

internal static string MakeStringBlock(string target, int firstLength)
internal static string MakeStringBlock(string target, int firstLength = 0)
{
const int maxChars = 74;
int maxCharsFirst = maxChars - firstLength + 1;
int maxCharsFirst = maxChars - firstLength;

// Construct the block
StringBuilder block = new();
int selectedMax = maxCharsFirst;
int processed = 0;
for (int currCharNum = 0; currCharNum < target.Length; currCharNum++)
{
if (target[currCharNum] != '\n' && target[currCharNum] != '\r')
{
block.Append(target[currCharNum]);
processed++;
}
if (processed >= selectedMax || target[currCharNum] == '\n')
{
// Append a new line because we reached the maximum limit
selectedMax = maxChars;
selectedMax = maxChars - 1;
processed = 0;
block.Append("\n ");
}
if (target[currCharNum] != '\n' && target[currCharNum] != '\r')
{
block.Append(target[currCharNum]);
processed++;
}
}
return block.ToString();
}
Expand Down
24 changes: 8 additions & 16 deletions VisualCard/Parts/CardBuilderTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,51 +57,43 @@ internal static string BuildArguments(string[] elementTypes, string valueType, i
bool installArguments = arguments.Length > 0;
bool installElementTypes = finalElementTypes.Length > 0;
bool installValueType = !string.IsNullOrEmpty(finalValue);
bool goOn = true;

// First, install the AltId parameter if it exists
if (installAltId)
{
argumentsBuilder.Append(VcardConstants._altIdArgumentSpecifier + altId);
noSemicolon = !installArguments && !installElementTypes && !installValueType;
if (noSemicolon)
{
argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString());
return argumentsBuilder.ToString();
}
goOn = false;
else
argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString());
}

// Then, install the element types parameter if it exists
if (installElementTypes)
if (installElementTypes && goOn)
{
argumentsBuilder.Append(VcardConstants._typeArgumentSpecifier + string.Join(",", finalElementTypes));
noSemicolon = !installArguments && !installValueType;
if (noSemicolon)
{
argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString());
return argumentsBuilder.ToString();
}
goOn = false;
else
argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString());
}

// Then, install the value type parameter if it exists
if (installValueType)
if (installValueType && goOn)
{
argumentsBuilder.Append(VcardConstants._valueArgumentSpecifier + string.Join(",", finalValue));
noSemicolon = !installArguments;
if (noSemicolon)
{
argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString());
return argumentsBuilder.ToString();
}
goOn = false;
else
argumentsBuilder.Append(VcardConstants._fieldDelimiter.ToString());
}

// Finally, install the remaining arguments if they exist and contain keys and values
if (installArguments)
if (installArguments && goOn)
{
List<string> finalArguments = [];
foreach (var arg in arguments)
Expand All @@ -111,7 +103,7 @@ internal static string BuildArguments(string[] elementTypes, string valueType, i

// We've reached the end.
argumentsBuilder.Append(VcardConstants._argumentDelimiter.ToString());
return argumentsBuilder.ToString();
return VcardCommonTools.MakeStringBlock(argumentsBuilder.ToString());
}
}
}

0 comments on commit 9af466c

Please sign in to comment.