public int IndexOf(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return(-1);
            }
            osUTF8 o = new osUTF8(s);

            return(IndexOf(o));
        }
示例#2
0
        public unsafe bool EndsWith(osUTF8 other)
        {
            int otherlen = other.m_len;

            if (otherlen > m_len)
            {
                return(false);

                fixed(byte *a = &m_data[m_offset], b = other.m_data)
                {
                    for (int i = otherlen - 1, j = m_len - 1; i >= 0; --i, --j)
                    {
                        if (a[j] != b[i])
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
        }
示例#3
0
        public unsafe bool StartsWith(osUTF8 other)
        {
            int otherlen = other.m_len;

            if (otherlen > m_len)
            {
                return(false);

                fixed(byte *a = &m_data[m_offset], b = other.m_data)
                {
                    for (int i = 0; i < otherlen; ++i)
                    {
                        if (a[i] != b[i])
                        {
                            return(false);
                        }
                    }
                }

                return(true);
        }
示例#4
0
 public osUTF8Slice(osUTF8 source)
 {
     m_data   = source.m_data;
     m_offset = 0;
     m_len    = source.Length;
 }
示例#5
0
        public bool EndsWith(string s)
        {
            osUTF8 other = new osUTF8(s); // yeack

            return(EndsWith(other));
        }
示例#6
0
        public bool StartsWith(string s)
        {
            osUTF8 other = new osUTF8(s); // yeack

            return(StartsWith(other));
        }
示例#7
0
 public osUTF8(osUTF8 source)
 {
     m_data = source.ToArray();
     m_len  = source.Length;
 }
示例#8
0
 public bool Contains(osUTF8 other)
 {
     return(IndexOf(other) > 0);
 }
 public osUTF8(osUTF8 source)
 {
     m_data   = source.m_data;
     m_offset = source.m_offset;
     m_len    = source.m_len;
 }
        //returns a segment view of main buffer
        public string SubString(int start, int len)
        {
            osUTF8 res = osUTF8SubString(start, len);

            return(res.ToString());
        }
        public bool Equals(string s)
        {
            osUTF8 o = new osUTF8(s);

            return(Equals(o));
        }
        public static bool TryParseUUID(osUTF8 inp, out UUID res, bool dashs = true)
        {
            res = UUID.Zero;
            osUTF8 t = new osUTF8(inp);

            t.SelfTrim();
            int len = t.m_len;

            if (len == 0)
            {
                return(false);
            }

            if (dashs)
            {
                if (len < 36)
                {
                    return(false);
                }
            }
            else
            {
                if (len < 32)
                {
                    return(false);
                }
            }

            byte[] data       = t.m_data;
            int    dataoffset = t.m_offset;

            int _a = 0;

            if (!Utils.TryHexToInt(data, dataoffset, 8, out _a))
            {
                return(false);
            }
            dataoffset += 8;

            if (dashs)
            {
                if (data[dataoffset] != (byte)'-')
                {
                    return(false);
                }
                ++dataoffset;
            }

            int n;

            if (!Utils.TryHexToInt(data, dataoffset, 4, out n))
            {
                return(false);
            }
            short _b = (short)n;

            dataoffset += 4;

            if (dashs)
            {
                if (data[dataoffset] != (byte)'-')
                {
                    return(false);
                }
                ++dataoffset;
            }

            if (!Utils.TryHexToInt(data, dataoffset, 4, out n))
            {
                return(false);
            }
            short _c = (short)n;

            dataoffset += 4;

            if (dashs)
            {
                if (data[dataoffset] != (byte)'-')
                {
                    return(false);
                }
                ++dataoffset;
            }

            if (!Utils.TryHexToInt(data, dataoffset, 4, out n))
            {
                return(false);
            }

            byte _d = (byte)(n >> 8);
            byte _e = (byte)n;

            dataoffset += 4;

            if (dashs)
            {
                if (data[dataoffset] != (byte)'-')
                {
                    return(false);
                }
                ++dataoffset;
            }

            if (!Utils.TryHexToInt(data, dataoffset, 8, out n))
                return(false); }
        public unsafe bool ReadLine(out osUTF8 line)
        {
            if (m_len == 0)
            {
                line = new osUTF8(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 osUTF8(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);
        }