Class AsciiString
Representation of a string with ASCII-only content.
AsciiString have the following characteristics:
They consist of valid ASCII characters (0-127) only.
They are immutable. Once constructed, an AsciiString cannot be modified. Methods which seem to perform "modifications" of the string like to_upper() etc. will always allocate a new instance and operate on that.
They are backed by native memory. This means that they can be used with zero/very low cost together with standard POSIX/libc functions like
puts
,memcmp
, etc.
Namespace: Perlang.Lang
Assembly: Perlang.Stdlib.dll
Syntax
public class AsciiString : String
Properties
| Improve this Doc View SourceItem[UIntPtr]
Declaration
public char this[nuint i] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.UIntPtr | i |
Property Value
Type | Description |
---|---|
System.Char |
Length
Declaration
public override nuint Length { get; }
Property Value
Type | Description |
---|---|
System.UIntPtr |
Overrides
Methods
| Improve this Doc View SourceEquals(Nullable<Object>)
Determines whether the specified object is equal to the current object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Object> | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
System.Boolean |
|
from(IReadOnlyList<Char>)
Initializes a new instance of the AsciiString class from an existing
Declaration
public static AsciiString from(IReadOnlyList<char> chars)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyList<System.Char> | chars | A char array, validated by the caller to be ASCII safe. |
Returns
Type | Description |
---|---|
AsciiString | A newly allocated AsciiString. |
from(String)
Creates a new AsciiString from the given .NET string. Note that this method will allocate a new backing buffer for holding the string contents; it will not reuse the existing bytes.
Declaration
public static AsciiString from(string s)
Parameters
Type | Name | Description |
---|---|---|
System.String | s | The input string. |
Returns
Type | Description |
---|---|
AsciiString | A newly allocated AsciiString. |
GetHashCode()
Gets a numerical hash for this AsciiString.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current AsciiString. |
to_upper()
Declaration
public override String to_upper()
Returns
Type | Description |
---|---|
String |
Overrides
| Improve this Doc View SourceToString()
Constructs a .NET string based on the given Perlang String.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A new .NET string. |
Overrides
Remarks
Note that this does not reuse the backing byte buffer for the string; it will cause a new byte buffer to be allocated and the Perlang String to be converted to .NET (UTF-16) format. This method should not be called in performance-critical code, and it should preferably be avoided altogether.
Operators
| Improve this Doc View SourceAddition(AsciiString, AsciiString)
Concatenates the given strings. This method will allocate a new AsciiString and the existing string data will be copied to it.
Declaration
public static AsciiString operator +(AsciiString a, AsciiString b)
Parameters
Type | Name | Description |
---|---|---|
AsciiString | a | The first string to concatenate. |
AsciiString | b | The second string to concatenate. |
Returns
Type | Description |
---|---|
AsciiString | A concatenated string ( |
Equality(AsciiString, AsciiString)
Determines whether the given strings are identical.
Declaration
public static bool operator ==(AsciiString a, AsciiString b)
Parameters
Type | Name | Description |
---|---|---|
AsciiString | a | The first string to compare, or |
AsciiString | b | The second string to compare, or |
Returns
Type | Description |
---|---|
System.Boolean |
|
Inequality(AsciiString, AsciiString)
Determined whether the given strings are non-identical.
Declaration
public static bool operator !=(AsciiString a, AsciiString b)
Parameters
Type | Name | Description |
---|---|---|
AsciiString | a | The first string to compare, or |
AsciiString | b | The second string to compare, or |
Returns
Type | Description |
---|---|
System.Boolean |
|