Skip to content

Commit b482316

Browse files
committed
Use char instead of string
1 parent 7a465a2 commit b482316

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4933
-2627
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#if NET40 || NETSTANDARD2_0
2+
namespace System;
3+
4+
/// <summary>
5+
/// Missing NET4_6_2 exts
6+
/// </summary>
7+
internal static class StringExtensions
8+
{
9+
/// <summary>
10+
/// Returns a new string in which all occurrences of a specified string in the current instance are replaced with
11+
/// another specified string, using the provided comparison type.
12+
/// </summary>
13+
public static bool Contains(this string commandText, string value, StringComparison comparisonType)
14+
=> !string.IsNullOrWhiteSpace(commandText) && commandText.IndexOf(value, comparisonType) >= 0;
15+
16+
/// <summary>
17+
/// Returns a new string in which all occurrences of a specified string in the current instance are replaced with
18+
/// another specified string, using the provided comparison type.
19+
/// </summary>
20+
public static string Replace(this string str, string oldValue, string newValue, StringComparison comparisonType)
21+
{
22+
newValue ??= string.Empty;
23+
24+
if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(oldValue) || oldValue.Equals(newValue, comparisonType))
25+
{
26+
return str;
27+
}
28+
29+
int foundAt;
30+
31+
while ((foundAt = str.IndexOf(oldValue, startIndex: 0, comparisonType)) != -1)
32+
{
33+
str = str.Remove(foundAt, oldValue.Length).Insert(foundAt, newValue);
34+
}
35+
36+
return str;
37+
}
38+
39+
/// <summary>
40+
/// Returns the hash code for this string using the specified rules.
41+
/// </summary>
42+
public static int GetHashCode(this string str, StringComparison comparisonType)
43+
=> comparisonType switch
44+
{
45+
StringComparison.CurrentCulture => StringComparer.CurrentCulture.GetHashCode(str),
46+
StringComparison.CurrentCultureIgnoreCase => StringComparer.CurrentCultureIgnoreCase.GetHashCode(str),
47+
StringComparison.InvariantCulture => StringComparer.InvariantCulture.GetHashCode(str),
48+
StringComparison.InvariantCultureIgnoreCase => StringComparer.InvariantCultureIgnoreCase.GetHashCode(str),
49+
StringComparison.Ordinal => StringComparer.Ordinal.GetHashCode(str),
50+
StringComparison.OrdinalIgnoreCase => StringComparer.OrdinalIgnoreCase.GetHashCode(str),
51+
_ => throw new NotSupportedException()
52+
};
53+
54+
/// <summary>
55+
/// Reports the zero-based index of the first occurrence of the specified string in the current String object. A
56+
/// parameter specifies the type of search to use for the specified string.
57+
/// </summary>
58+
public static int IndexOf(this string text, char value, StringComparison comparisonType)
59+
=> text.IndexOf(value.ToString(CultureInfo.InvariantCulture), comparisonType);
60+
61+
/// <summary>
62+
/// Determines whether the end of this string instance matches the specified string when compared using the specified
63+
/// comparison option.
64+
/// </summary>
65+
public static bool EndsWith(this string text,
66+
char value,
67+
StringComparison comparisonType = StringComparison.Ordinal)
68+
=> text.EndsWith(value.ToString(CultureInfo.InvariantCulture), comparisonType);
69+
70+
/// <summary>
71+
/// Determines whether the beginning of this string instance matches the specified string when compared using the
72+
/// specified comparison option.
73+
/// </summary>
74+
public static bool StartsWith(this string text,
75+
char value,
76+
StringComparison comparisonType = StringComparison.Ordinal)
77+
=> text.StartsWith(value.ToString(CultureInfo.InvariantCulture), comparisonType);
78+
}
79+
#endif

src/iTextSharp.LGPLv2.Core/iTextSharp/text/Anchor.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Anchor : Phrase
2828
/// <overloads>
2929
/// Has nine overloads.
3030
/// </overloads>
31-
public Anchor() : base(16)
31+
public Anchor() : base(leading: 16)
3232
{
3333
}
3434

@@ -104,6 +104,7 @@ public Anchor(float leading, string str, Font font) : base(leading, str, font)
104104
public Anchor(Phrase phrase) : base(phrase)
105105
{
106106
var anchor = phrase as Anchor;
107+
107108
if (anchor != null)
108109
{
109110
var a = anchor;
@@ -124,8 +125,9 @@ public override IList<Chunk> Chunks
124125
get
125126
{
126127
var tmp = new List<Chunk>();
127-
var localDestination = reference != null && reference.StartsWith("#", StringComparison.Ordinal);
128+
var localDestination = reference != null && reference.StartsWith(value: '#');
128129
var notGotoOk = true;
130+
129131
foreach (Chunk chunk in this)
130132
{
131133
if (name != null && notGotoOk && !chunk.IsEmpty())
@@ -136,7 +138,7 @@ public override IList<Chunk> Chunks
136138

137139
if (localDestination)
138140
{
139-
chunk.SetLocalGoto(reference.Substring(1));
141+
chunk.SetLocalGoto(reference.Substring(startIndex: 1));
140142
}
141143
else if (reference != null)
142144
{
@@ -215,8 +217,9 @@ public override bool Process(IElementListener listener)
215217

216218
try
217219
{
218-
var localDestination = reference != null && reference.StartsWith("#", StringComparison.Ordinal);
220+
var localDestination = reference != null && reference.StartsWith(value: '#');
219221
var notGotoOk = true;
222+
220223
foreach (var chunk in Chunks)
221224
{
222225
if (name != null && notGotoOk && !chunk.IsEmpty())
@@ -227,7 +230,7 @@ public override bool Process(IElementListener listener)
227230

228231
if (localDestination)
229232
{
230-
chunk.SetLocalGoto(reference.Substring(1));
233+
chunk.SetLocalGoto(reference.Substring(startIndex: 1));
231234
}
232235
else if (reference != null)
233236
{

0 commit comments

Comments
 (0)