Skip to content

Commit 2241c8a

Browse files
authored
Merge pull request #343 from sideeffffect/master
Wrapper around String
2 parents f1ec03c + 96a2442 commit 2241c8a

4 files changed

Lines changed: 202 additions & 2 deletions

File tree

src/FSharpx.Extras/FSharpx.Extras.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="AssemblyInfo.fs" />
6161
<Compile Include="Prelude.fs" />
6262
<Compile Include="Pluralizer.fs" />
63+
<Compile Include="String.fs" />
6364
<Compile Include="Strings.fs" />
6465
<Compile Include="IO.fs" />
6566
<Compile Include="Monoid.fs" />

src/FSharpx.Extras/String.fs

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
namespace FSharpx
2+
3+
open System
4+
5+
/// Functional wrappers around String instance methods
6+
module String =
7+
8+
/// Returns a value indicating whether a specified substring occurs within this string.
9+
let inline contains value (s:string) = s.Contains(value)
10+
11+
/// Compares two specified String objects and returns an integer that indicates their relative position in the sort order.
12+
let inline compare (comparisonType:StringComparison) strA strB = String.Compare(strA, strB, comparisonType)
13+
14+
/// Compares two specified String objects and returns an integer that indicates their relative position in the sort order. Compare strings using ordinal (binary) sort rules and ignoring the case of the strings being compared.
15+
let inline compareIgnoreCase strA strB = compare StringComparison.OrdinalIgnoreCase strA strB
16+
17+
/// Determines whether the end of this string instance matches the specified string.
18+
let inline endsWith value (s:string) = s.EndsWith(value)
19+
20+
/// Determines whether the end of this string instance matches the specified string when compared using the specified culture.
21+
let inline endsWith' value ignoreCase culture (s:string) = s.EndsWith(value, ignoreCase, culture)
22+
23+
/// Determines whether the end of this string instance matches the specified string when compared using the specified comparison option.
24+
let inline endsWith'' value comparisonType (s:string) = s.EndsWith(value, comparisonType)
25+
26+
/// Determines whether two specified String objects have the same value.
27+
let inline equals (comparisonType:StringComparison) a b = String.Equals(a, b, comparisonType)
28+
29+
/// Determines whether two specified String objects have the same value. Compare strings using ordinal (binary) sort rules and ignoring the case of the strings being compared.
30+
let inline equalsIgnoreCase a b = equals StringComparison.OrdinalIgnoreCase a b
31+
32+
/// Reports the zero-based index of the first occurrence of the specified Unicode character in this string.
33+
let inline indexOfChar (value:char) (s:string) = s.IndexOf(value)
34+
35+
/// Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The search starts at a specified character position.
36+
let inline indexOfChar' (value:char) startIndex (s:string) = s.IndexOf(value, startIndex)
37+
38+
/// Reports the zero-based index of the first occurrence of the specified character in this instance. The search starts at a specified character position and examines a specified number of character positions.
39+
let inline indexOfChar'' (value:char) startIndex count (s:string) = s.IndexOf(value, startIndex, count)
40+
41+
/// Reports the zero-based index of the first occurrence of the specified string in this instance.
42+
let inline indexOfString (value:string) (s:string) = s.IndexOf(value)
43+
44+
/// Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position.
45+
let inline indexOfString' (value:string) (startIndex:int) (s:string) = s.IndexOf(value, startIndex)
46+
47+
/// Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position and examines a specified number of character positions.
48+
let inline indexOfString'' (value:string) (startIndex:int) (count:int) (s:string) = s.IndexOf(value, startIndex, count)
49+
50+
/// Reports the zero-based index of the first occurrence of the specified string in the current String object. A parameter specifies the type of search to use for the specified string.
51+
let inline indexOfStringWithComparison value (comparisonType:StringComparison) (s:string) = s.IndexOf(value, comparisonType)
52+
53+
/// Reports the zero-based index of the first occurrence of the specified string in the current String object. Parameters specify the starting search position in the current string and the type of search to use for the specified string.
54+
let inline indexOfStringWithComparison' value startIndex (comparisonType:StringComparison) (s:string) = s.IndexOf(value, startIndex, comparisonType)
55+
56+
/// Reports the zero-based index of the first occurrence of the specified string in the current String object. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string.
57+
let inline indexOfStringWithComparison'' value startIndex count comparisonType (s:string) = s.IndexOf(value, startIndex, count, comparisonType)
58+
59+
/// Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters.
60+
let inline indexOfAny anyOf (s:string) = s.IndexOfAny(anyOf)
61+
62+
/// Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position.
63+
let inline indexOfAny' anyOf startIndex (s:string) = s.IndexOfAny(anyOf, startIndex)
64+
65+
/// Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position and examines a specified number of character positions.
66+
let inline indexOfAny'' anyOf startIndex count (s:string) = s.IndexOfAny(anyOf, startIndex, count)
67+
68+
/// Returns a new string in which a specified string is inserted at a specified index position in this instance.
69+
let inline insert startIndex value (s:string) = s.Insert(startIndex, value)
70+
71+
/// Indicates whether this string is in Unicode normalization form C.
72+
let inline isNormalized (s:string) = s.IsNormalized()
73+
74+
/// Indicates whether this string is in the specified Unicode normalization form.
75+
let inline isNormalized' normalizationForm (s:string) = s.IsNormalized(normalizationForm)
76+
77+
/// Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance.
78+
let inline lastIndexOfChar (value:char) (s:string) = s.LastIndexOf(value)
79+
80+
/// Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string.
81+
let inline lastIndexOfChar' (value:char) startIndex (s:string) = s.LastIndexOf(value, startIndex)
82+
83+
/// Reports the zero-based index position of the last occurrence of the specified Unicode character in a substring within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions.
84+
let inline lastIndexOfChar'' (value:char) startIndex count (s:string) = s.LastIndexOf(value, startIndex, count)
85+
86+
/// Reports the zero-based index position of the last occurrence of a specified string within this instance.
87+
let inline lastIndexOfString (value:string) (s:string) = s.LastIndexOf(value)
88+
89+
/// Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string.
90+
let inline lastIndexOfString' (value:string) (startIndex:int) (s:string) = s.LastIndexOf(value, startIndex)
91+
92+
/// Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions.
93+
let inline lastIndexOfString'' (value:string) (startIndex:int) (count:int) (s:string) = s.LastIndexOf(value, startIndex, count)
94+
95+
/// Reports the zero-based index of the last occurrence of a specified string within the current String object. A parameter specifies the type of search to use for the specified string.
96+
let inline lastIndexOfStringWithComparison value (comparisonType:StringComparison) (s:string) = s.LastIndexOf(value, comparisonType)
97+
98+
/// Reports the zero-based index of the last occurrence of a specified string within the current String object. The search starts at a specified character position and proceeds backward toward the beginning of the string. A parameter specifies the type of comparison to perform when searching for the specified string.
99+
let inline lastIndexOfStringWithComparison' value startIndex (comparisonType:StringComparison) (s:string) = s.LastIndexOf(value, startIndex, comparisonType)
100+
101+
/// Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for the specified number of character positions. A parameter specifies the type of comparison to perform when searching for the specified string.
102+
let inline lastIndexOfStringWithComparison'' value startIndex count (comparisonType:StringComparison) (s:string) = s.LastIndexOf(value, startIndex, count, comparisonType)
103+
104+
/// Returns a new string whose textual value is the same as this string, but whose binary representation is in Unicode normalization form C.
105+
let inline normalize (s:string) = s.Normalize()
106+
107+
/// Returns a new string whose textual value is the same as this string, but whose binary representation is in the specified Unicode normalization form.
108+
let inline normalize' normalizationForm (s:string) = s.Normalize(normalizationForm)
109+
110+
/// Returns a new string that right-aligns the characters in this instance by padding them with spaces on the left, for a specified total length.
111+
let inline padLeft totalWidth (s:string) = s.PadLeft(totalWidth)
112+
113+
/// Returns a new string that right-aligns the characters in this instance by padding them on the left with a specified Unicode character, for a specified total length.
114+
let inline padLeft' totalWidth paddingChar (s:string) = s.PadLeft(totalWidth, paddingChar)
115+
116+
/// Returns a new string that left-aligns the characters in this string by padding them with spaces on the right, for a specified total length.
117+
let inline padRight totalWidth (s:string) = s.PadRight(totalWidth)
118+
119+
/// Returns a new string that left-aligns the characters in this string by padding them on the right with a specified Unicode character, for a specified total length.
120+
let inline padRight' totalWidth paddingChar (s:string) = s.PadRight(totalWidth, paddingChar)
121+
122+
/// Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.
123+
let inline remove startIndex (s:string) = s.Remove(startIndex)
124+
125+
/// Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.
126+
let inline remove' startIndex count (s:string) = s.Remove(startIndex, count)
127+
128+
/// Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character.
129+
let inline replace (oldChar:char) (newChar:char) (s:string) = s.Replace(oldChar, newChar)
130+
131+
/// Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string.
132+
let inline replace' (oldValue:string) (newValue:string) (s:string) = s.Replace(oldValue, newValue)
133+
134+
/// Splits a string into substrings that are based on the characters in an array.
135+
let inline splitChar separator (s:string) = s.Split(separator)
136+
137+
/// Splits a string into a maximum number of substrings based on the characters in an array. You also specify the maximum number of substrings to return.
138+
let inline splitChar' separator (count:int) (s:string) = s.Split(separator, count)
139+
140+
/// Splits a string into substrings based on the characters in an array. You can specify whether the substrings include empty array elements.
141+
let inline splitCharWithOptions (separator:char[]) (options:StringSplitOptions) (s:string) = s.Split(separator, options)
142+
143+
/// Splits a string into a maximum number of substrings based on the characters in an array.
144+
let inline splitCharWithOptions' (separator:char[]) count (options:StringSplitOptions) (s:string) = s.Split(separator, count, options)
145+
146+
/// Splits a string into substrings based on the strings in an array. You can specify whether the substrings include empty array elements.
147+
let inline splitString (separator:string[]) (options:StringSplitOptions) (s:string) = s.Split(separator, options)
148+
149+
/// Splits a string into a maximum number of substrings based on the strings in an array. You can specify whether the substrings include empty array elements.
150+
let inline splitString' (separator:string[]) count (options:StringSplitOptions) (s:string) = s.Split(separator, count, options)
151+
152+
/// Determines whether the beginning of this string instance matches the specified string.
153+
let inline startsWith value (s:string) = s.StartsWith(value)
154+
155+
/// Determines whether the beginning of this string instance matches the specified string when compared using the specified comparison option.
156+
let inline startsWith' value comparisonType (s:string) = s.StartsWith(value, comparisonType)
157+
158+
/// Determines whether the beginning of this string instance matches the specified string when compared using the specified culture.
159+
let inline startsWith'' value ignoreCase culture (s:string) = s.StartsWith(value, ignoreCase, culture)
160+
161+
/// Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string.
162+
let inline substring startIndex (s:string) = s.Substring(startIndex)
163+
164+
/// Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length.
165+
let inline substring' startIndex length (s:string) = s.Substring(startIndex, length)
166+
167+
/// Copies the characters in this instance to a Unicode character array.
168+
let inline toCharArray (s:string) = s.ToCharArray()
169+
170+
/// Copies the characters in a specified substring in this instance to a Unicode character array.
171+
let inline toCharArray' startIndex length (s:string) = s.ToCharArray(startIndex, length)
172+
173+
/// Returns a copy of this string converted to lowercase.
174+
let inline toLower (s:string) = s.ToLower()
175+
176+
/// Returns a copy of this string converted to lowercase, using the casing rules of the specified culture.
177+
let inline toLower' culture (s:string) = s.ToLower(culture)
178+
179+
/// Returns a copy of this String object converted to lowercase using the casing rules of the invariant culture.
180+
let inline toLowerInvariant (s:string) = s.ToLowerInvariant()
181+
182+
/// Returns a copy of this string converted to uppercase.
183+
let inline toUpper (s:string) = s.ToUpper()
184+
185+
/// Returns a copy of this string converted to uppercase, using the casing rules of the specified culture.
186+
let inline toUpper' culture (s:string) = s.ToUpper(culture)
187+
188+
/// Returns a copy of this String object converted to uppercase using the casing rules of the invariant culture.
189+
let inline toUpperInvariant (s:string) = s.ToUpperInvariant()
190+
191+
/// Removes all leading and trailing white-space characters from the current String object.
192+
let inline trim (s:string) = s.Trim()
193+
194+
/// Removes all leading and trailing occurrences of a set of characters specified in an array from the current String object.
195+
let inline trim' trimChars (s:string) = s.Trim(trimChars)
196+
197+
/// Removes all trailing occurrences of a set of characters specified in an array from the current String object.
198+
let inline trimEnd trimChars (s:string) = s.TrimEnd(trimChars)
199+
200+
/// Removes all leading occurrences of a set of characters specified in an array from the current String object.
201+
let inline trimStart trimChars (s:string) = s.TrimStart(trimChars)

tmp.bin

Lines changed: 0 additions & 1 deletion
This file was deleted.

tmp.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)