Ejemplo n.º 1
0
    public bool EndsWith(Utf8String other)
    {
        var otherLength = other.Length;
        var offset      = Length - otherLength;

        return(offset >= 0 && ByteStringFunctions.Equals(other.Path, otherLength, Path + offset, otherLength));
    }
Ejemplo n.º 2
0
    // Join a number of strings with a given byte between them.
    public static Utf8String Join(byte splitter, params Utf8String[] strings)
    {
        var length = strings.Sum(s => s.Length) + strings.Length;
        var data   = ( byte * )Marshal.AllocHGlobal(length);

        var  ptr     = data;
        bool?isLower = ByteStringFunctions.AsciiIsLower(splitter);
        bool?isAscii = splitter < 128;

        foreach (var s in strings)
        {
            Functions.MemCpyUnchecked(ptr, s.Path, s.Length);
            ptr += s.Length;
            *ptr++ = splitter;
            isLower  = Combine(isLower, s.IsAsciiLowerInternal);
            isAscii &= s.IsAscii;
        }

        --length;
        data[length] = 0;
        var ret = FromByteStringUnsafe(data, length, true, isLower, isAscii);

        ret._length |= OwnedFlag;
        return(ret);
    }
Ejemplo n.º 3
0
    // Create a owned copy of the string and replace all occurences of from with to in it.
    public Utf8String Replace(byte from, byte to)
    {
        var length      = Length;
        var newPtr      = ByteStringFunctions.CopyString(_path, length);
        var numReplaced = ByteStringFunctions.Replace(newPtr, length, from, to);

        return(new Utf8String().Setup(newPtr, length, numReplaced == 0 ? _crc32 : null, true, true, IsAsciiLowerInternal, IsAsciiInternal));
    }
Ejemplo n.º 4
0
    // Create an owned copy of the given string.
    public Utf8String Clone()
    {
        var ret = new Utf8String();

        ret._length = _length | OwnedFlag | NullTerminatedFlag;
        ret._path   = ByteStringFunctions.CopyString(Path, Length);
        ret._crc32  = Crc32;
        return(ret);
    }
Ejemplo n.º 5
0
    public bool Equals(Utf8String?other)
    {
        if (ReferenceEquals(null, other))
        {
            return(false);
        }

        if (ReferenceEquals(this, other))
        {
            return(true);
        }

        return(_crc32 == other._crc32 && ByteStringFunctions.Equals(_path, Length, other._path, other.Length));
    }
Ejemplo n.º 6
0
    public int CompareTo(Utf8String?other)
    {
        if (ReferenceEquals(this, other))
        {
            return(0);
        }

        if (ReferenceEquals(null, other))
        {
            return(1);
        }

        return(ByteStringFunctions.Compare(_path, Length, other._path, other.Length));
    }
Ejemplo n.º 7
0
    public int CompareToCi(Utf8String?other)
    {
        if (ReferenceEquals(null, other))
        {
            return(0);
        }

        if (ReferenceEquals(this, other))
        {
            return(1);
        }

        if ((IsAsciiLowerInternal ?? false) && (other.IsAsciiLowerInternal ?? false))
        {
            return(ByteStringFunctions.Compare(_path, Length, other._path, other.Length));
        }

        return(ByteStringFunctions.AsciiCaselessCompare(_path, Length, other._path, other.Length));
    }
Ejemplo n.º 8
0
    public bool EqualsCi(Utf8String?other)
    {
        if (ReferenceEquals(null, other))
        {
            return(false);
        }

        if (ReferenceEquals(this, other))
        {
            return(true);
        }

        if ((IsAsciiLowerInternal ?? false) && (other.IsAsciiLowerInternal ?? false))
        {
            return(_crc32 == other._crc32 && ByteStringFunctions.Equals(_path, Length, other._path, other.Length));
        }

        return(ByteStringFunctions.AsciiCaselessEquals(_path, Length, other._path, other.Length));
    }
Ejemplo n.º 9
0
 public static ResourceType FromBytes(byte a1, byte a2, byte a3, byte a4)
 => ( ResourceType )((( uint )ByteStringFunctions.AsciiToLower(a1) << 24)
                     | (( uint )ByteStringFunctions.AsciiToLower(a2) << 16)
                     | (( uint )ByteStringFunctions.AsciiToLower(a3) << 8)
                     | ByteStringFunctions.AsciiToLower(a4));
Ejemplo n.º 10
0
    public bool StartsWith(Utf8String other)
    {
        var otherLength = other.Length;

        return(otherLength <= Length && ByteStringFunctions.Equals(other.Path, otherLength, Path, otherLength));
    }
Ejemplo n.º 11
0
 // Convert the ascii portion of the string to lowercase.
 // Guaranteed to create an owned copy.
 public Utf8String AsciiToLowerClone()
 => (_length & AsciiLowerFlag) == 0
         ? new Utf8String().Setup(ByteStringFunctions.AsciiToLower(_path, Length), Length, null, true, true, true, IsAsciiInternal)
         : Clone();