-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringViewExtensions.cs
More file actions
42 lines (39 loc) · 1.82 KB
/
StringViewExtensions.cs
File metadata and controls
42 lines (39 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace Ramstack.Text;
/// <summary>
/// Provides extension methods for the <see cref="StringView"/> structure.
/// </summary>
public static class StringViewExtensions
{
/// <summary>
/// Creates a new <see cref="StringView"/> over a string.
/// </summary>
/// <param name="value">The string to create a view over.</param>
/// <returns>
/// A <see cref="StringView"/> representing the specified string.
/// </returns>
public static StringView AsView(this string? value) =>
new(value ?? "");
/// <summary>
/// Creates a new <see cref="StringView"/> over a portion of the specified string
/// starting at a specified position to the end of the string.
/// </summary>
/// <param name="value">The string to create a view over.</param>
/// <param name="index">The zero-based starting position of the view in the string.</param>
/// <returns>
/// A <see cref="StringView"/> representing the specified portion of the string.
/// </returns>
public static StringView AsView(this string? value, int index) =>
new(value ?? "", index);
/// <summary>
/// Creates a new <see cref="StringView"/> over a portion of the specified string
/// starting at a specified position for a specified number of characters.
/// </summary>
/// <param name="value">The string to create a view over.</param>
/// <param name="index">The zero-based starting position of the view in the string.</param>
/// <param name="length">The number of characters to include in the view.</param>
/// <returns>
/// A <see cref="StringView"/> representing the specified portion of the string.
/// </returns>
public static StringView AsView(this string? value, int index, int length) =>
new(value ?? "", index, length);
}