public osUTF8Slice TrimEnd() { osUTF8Slice ret = new osUTF8Slice(this); ret.SelfTrimEnd(); return(ret); }
public unsafe bool ACSIILowerEquals(osUTF8Slice o) { if (o == null || m_len != o.m_len) { return(false); fixed(byte *a = m_data, b = o.m_data) { byte *ptr = a; byte *end = ptr + m_len; byte *ptrb = b + o.m_offset; while (ptr < end) { byte c = *ptr; if (c >= 0x41 && c <= 0x5a) { c |= 0x20; } if (c != *ptrb) { return(false); } ++ptr; ++ptrb; } } return(true); }
public osUTF8Slice Concat(osUTF8Slice other) { byte[] b = new byte[m_len + other.m_len]; Array.Copy(m_data, m_offset, b, 0, m_len); Array.Copy(other.m_data, other.m_offset, b, m_len, other.m_len); return(new osUTF8Slice(b, 0, m_len + other.m_len)); }
public unsafe int IndexOf(osUTF8Slice other) { int otherlen = other.m_len; if (otherlen > m_len || otherlen == 0) { return(-1); } byte[] otherdata = other.m_data; fixed(byte *a = &m_data[m_offset], b = &otherdata[other.m_offset]) { for (int i = 0; i < m_len - otherlen; ++i) { int k = 0; for (int j = i; k < otherlen; ++k, ++j) { if (a[j] != b[k]) { break; } } if (k == otherlen) { return(i); } } return(-1); } }
public osUTF8Slice TrimStart(byte[] v) { osUTF8Slice ret = new osUTF8Slice(this); ret.SelfTrimStart(v); return(ret); }
public osUTF8Slice[] Split(char[] b, bool ignoreEmpty = true) { if (m_len == 0) { return(new osUTF8Slice[] { this }); } bool incEmpty = !ignoreEmpty; osUTF8Slice tmp = new osUTF8Slice(this); List <osUTF8Slice> lst = new List <osUTF8Slice>(); int indx; while ((indx = tmp.IndexOfAny(b)) >= 0) { osUTF8Slice o = tmp.SubUTF8(0, indx); if (incEmpty) { lst.Add(o); } else if (o.m_len > 0) { lst.Add(o); } tmp.MoveStart(indx + 1); } if (tmp.m_len > 0) { lst.Add(tmp); } return(lst.ToArray()); }
public osUTF8Slice TrimEnd(char[] v) { osUTF8Slice ret = new osUTF8Slice(this); ret.SelfTrimEnd(v); return(ret); }
public unsafe bool Equals(osUTF8Slice o) { if (o == null || m_len != o.m_len) { return(false); } byte[] otherdata = o.m_data; if (m_len < 8) { for (int i = m_offset, j = o.m_offset; i < m_offset + m_len; ++i, ++j) { if (m_data[i] != otherdata[j]) { return(false); } } return(true); } fixed(byte *a = &m_data[m_offset], b = &otherdata[o.m_offset]) { for (int i = 0; i < m_len; ++i) { if (a[i] != b[i]) { return(false); } } } return(true); }
public osUTF8Slice Trim(byte b) { osUTF8Slice ret = new osUTF8Slice(this); ret.SelfTrimStart(b); ret.SelfTrimEnd(b); return(ret); }
public void Append(osUTF8Slice b) { int indx = m_offset + m_len; int nbytes = b.m_len; CheckCapacity(ref indx, nbytes); Array.Copy(b.m_data, b.m_offset, m_data, indx, nbytes); m_len += nbytes; }
public static unsafe bool IsNullOrWhitespace(osUTF8Slice u) { if (u == null || u.m_len == 0) { return(true); } byte[] data = u.m_data; for (int i = u.m_offset; i < u.m_offset + u.m_len; ++i) { if (data[i] != 0x20) { return(false); } } return(true); }
public unsafe bool EndsWith(osUTF8Slice other) { int otherlen = other.m_len; if (otherlen > m_len) { return(false); fixed(byte *a = &m_data[m_offset], b = &other.m_data[other.m_offset]) { for (int i = otherlen - 1, j = m_len - 1; i >= 0; --i, --j) { if (a[j] != b[i]) { return(false); } } return(true); } }
public unsafe bool StartsWith(osUTF8Slice other) { int otherlen = other.m_len; if (otherlen > m_len) { return(false); fixed(byte *a = &m_data[m_offset], b = &other.m_data[other.m_offset]) { for (int i = 0; i < otherlen; ++i) { if (a[i] != b[i]) { return(false); } } } return(true); }
public static bool IsEmpty(osUTF8Slice u) { return(u == null || u.m_len == 0); }
public unsafe bool ReadLine(out osUTF8Slice line) { if (m_len == 0) { line = new osUTF8Slice(new byte[0], 0, 0); return(false); } int lineend = -1; byte b = 0; if (m_len < 8) { for (int i = m_offset; i < m_offset + m_len; ++i) { b = m_data[i]; if (b == (byte)'\r' || b == (byte)'\n') { if (i > 0 && m_data[i - 1] == (byte)'\\') { continue; } lineend = i; break; } } } else { fixed(byte *a = &m_data[m_offset]) { for (int i = 0; i < m_len; ++i) { b = a[i]; if (b == (byte)'\r' || b == (byte)'\n') { if (i > 0 && a[i - 1] == (byte)'\\') { continue; } lineend = i + m_offset; break; } } } } line = new osUTF8Slice(m_data, m_offset, m_len); if (lineend < 0) { m_offset = m_offset + m_len - 1; m_len = 0; return(false); } int linelen = lineend - m_offset; line.m_len = linelen; ++linelen; if (linelen >= m_len) { m_offset = m_offset + m_len - 1; m_len = 0; return(true); } m_offset += linelen; m_len -= linelen; if (m_len <= 0) { m_len = 0; return(true); } if (b == (byte)'\r') { if (m_data[m_offset] == (byte)'\n') { ++m_offset; --m_len; } } if (m_len <= 0) { m_len = 0; } return(true); }
public bool Contains(osUTF8Slice other) { return(IndexOf(other) > 0); }
public osUTF8Slice TrimStart() { osUTF8Slice ret = new osUTF8Slice(this); return(ret.TrimStart()); }
public osUTF8Slice Trim(byte b) { osUTF8Slice ret = new osUTF8Slice(this); return(ret.Trim(b)); }
public osUTF8Slice Trim(char[] v) { osUTF8Slice ret = new osUTF8Slice(this); return(ret.Trim(v)); }
public osUTF8Slice TrimEnd(byte[] v) { osUTF8Slice ret = new osUTF8Slice(this); return(ret.TrimEnd(v)); }
//returns a segment view of main buffer public string SubString(int start, int len) { osUTF8Slice res = SubUTF8(start, len); return(res.ToString()); }
public osUTF8(osUTF8Slice source) { m_data = source.ToArray(); m_len = m_data.Length; }
public osUTF8Slice(osUTF8Slice source) { m_data = source.m_data; m_offset = source.m_offset; m_len = source.m_len; }
public osUTF8Slice SubUTF8(int start, int len) { osUTF8Slice oss = new osUTF8Slice(this); return(oss.SubUTF8(start, len)); }
public bool EndsWith(string s) { osUTF8Slice other = new osUTF8Slice(s); // yeack return(EndsWith(other)); }
public string SubString(int start, int len) { osUTF8Slice oss = new osUTF8Slice(this); return(oss.SubString(start, len)); }