コード例 #1
0
ファイル: StringBlob.cs プロジェクト: nmoschkin/dtlib-net5
        /// <summary>
        /// Returns the length of the string at the specified index.
        /// </summary>
        /// <param name="index">The length of the specified string.</param>
        /// <returns></returns>
        public int get_LengthAt(int index)
        {
            int LengthAtRet = default;

            if (index >= Count)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (_dynamic)
            {
                Refresh();
            }
            if (_lpwstr)
            {
                var lpsz = new LPWSTR();
                lpsz._ptr   = _index[index];
                LengthAtRet = lpsz.Length;
                GC.SuppressFinalize(lpsz);
            }
            else
            {
                var lpsz = new BSTR();
                lpsz._ptr   = _index[index];
                LengthAtRet = lpsz.Length;
                GC.SuppressFinalize(lpsz);
            }

            return(LengthAtRet);
        }
コード例 #2
0
ファイル: StringBlob.cs プロジェクト: nmoschkin/dtlib-net5
        /// <summary>
        /// Returns the current count of strings, walking the buffer, if necessary.
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            int GetCountRet = default;
            int l           = 0;

            if (SafePtr.handle == IntPtr.Zero)
            {
                return(0);
            }
            if (_lpwstr)
            {
                var    lpsz = new LPWSTR();
                MemPtr m;
                lpsz._ptr = _mem.handle;
                do
                {
                    if (Conversions.ToBoolean(lpsz.Length))
                    {
                        l += 1;
                    }
                    lpsz._ptr = lpsz._ptr + (lpsz.Length * 2 + 2);
                    m         = lpsz._ptr;
                    if (m.get_ShortAt(0L) == 0)
                    {
                        break;
                    }
                }while (true);
                GC.SuppressFinalize(lpsz);
            }
            else
            {
                switch (SizeDescriptorLength)
                {
                case 2:
                {
                    l = _mem.get_UShortAt(0L);
                    break;
                }

                case 4:
                {
                    l = (int)_mem.get_UIntegerAt(0L);
                    break;
                }

                case 8:
                {
                    l = (int)_mem.get_LongAt(0L);
                    break;
                }
                }
            }

            GetCountRet = l;
            _count      = l;
            return(GetCountRet);
        }
コード例 #3
0
ファイル: StringBlob.cs プロジェクト: nmoschkin/dtlib-net5
        /// <summary>
        /// Recounts the strings and updates all preamble data and metadata.
        /// </summary>
        /// <returns>An array of IntPtr's to the absolute memory addresses of all strings.</returns>
        public IntPtr[] Refresh()
        {
            IntPtr[] RefreshRet = default;
            int      c          = GetCount();

            IntPtr[] by;
            by = new IntPtr[c];
            if (_lpwstr)
            {
                var lpsz = new LPWSTR();
                lpsz._ptr = _mem;
                for (int l = 0, loopTo = c - 1; l <= loopTo; l++)
                {
                    by[l]     = (IntPtr)lpsz._ptr.ToInt64();
                    lpsz._ptr = lpsz._ptr + (lpsz.Length * 2 + 2);
                }

                RefreshRet = by;
                GC.SuppressFinalize(lpsz);
            }
            else
            {
                var lpsz = new BSTR();
                lpsz._preamble = SizeDescriptorLength;
                lpsz._ptr      = _mem.handle + SizeDescriptorLength;
                for (int l = 0, loopTo1 = c - 1; l <= loopTo1; l++)
                {
                    by[l]     = (IntPtr)lpsz._ptr.ToInt64();
                    lpsz._ptr = lpsz._ptr + (lpsz.Length * 2 + lpsz._preamble);
                }

                RefreshRet = by;
                GC.SuppressFinalize(lpsz);
            }

            _index = by;
            return(RefreshRet);
        }
コード例 #4
0
ファイル: StringBlob.cs プロジェクト: nmoschkin/dtlib-net5
        /// <summary>
        /// Formats the StringBlob into a single string using the specified criteria.
        /// </summary>
        /// <param name="format">A combination of <see cref="StringBlobFormats"/> values that indicate how the string will be rendered.</param>
        /// <param name="customFormat">(NOT IMPLEMENTED)</param>
        /// <returns></returns>
        public string ToFormattedString(StringBlobFormats format, string customFormat = "")
        {
            var  c = default(long);
            long d;
            long x  = 0L;
            var  sb = new StringBuilder();

            if (_dynamic)
            {
                Refresh();
            }
            if (Conversions.ToBoolean(format & StringBlobFormats.Commas))
            {
                c += (_count - 1) * 2;
            }

            if (Conversions.ToBoolean(format & StringBlobFormats.Quoted))
            {
                c += 4 * _count;
            }

            if (Conversions.ToBoolean(format & StringBlobFormats.CrLf))
            {
                c += 4 * _count;
            }

            if (Conversions.ToBoolean(format & StringBlobFormats.Spaced))
            {
                c += (_count - 1) * 2;
            }

            d = _mem.Length;
            if (_lpwstr)
            {
                d -= 2L;
                d -= 2 * _count;
            }
            else
            {
                d -= SizeDescriptorLength;
                d -= SizeDescriptorLength * _count;
            }

            c          += d;
            sb.Capacity = (int)c;
            if (_lpwstr)
            {
                var lpstr = new LPWSTR();
                for (int i = 0, loopTo = _count - 1; i <= loopTo; i++)
                {
                    if (i > 0)
                    {
                        if (Conversions.ToBoolean(format & StringBlobFormats.Commas))
                        {
                            sb.Append(",");
                            x += 1L;
                        }

                        if (Conversions.ToBoolean(format & StringBlobFormats.Spaced))
                        {
                            sb.Append(" ");
                            x += 1L;
                        }
                    }

                    if (Conversions.ToBoolean(format & StringBlobFormats.Quoted))
                    {
                        sb.Append("\"");
                        x += 1L;
                    }

                    lpstr._ptr = (IntPtr)_index[i].ToInt64();
                    sb.Append(lpstr.Text);
                    x += lpstr.Length;
                    if (Conversions.ToBoolean(format & StringBlobFormats.Quoted))
                    {
                        sb.Append("\"");
                        x += 1L;
                    }

                    if (Conversions.ToBoolean(format & StringBlobFormats.CrLf))
                    {
                        sb.Append(Constants.vbCr);
                        x += 1L;
                        sb.Append(Constants.vbLf);
                        x += 1L;
                    }
                }

                GC.SuppressFinalize(lpstr);
            }
            else
            {
                var lpstr = new BSTR();
                lpstr._preamble = SizeDescriptorLength;
                for (int i = 0, loopTo1 = _count - 1; i <= loopTo1; i++)
                {
                    if (i > 0)
                    {
                        if (Conversions.ToBoolean(format & StringBlobFormats.Commas))
                        {
                            sb.Append(",");
                            x += 1L;
                        }

                        if (Conversions.ToBoolean(format & StringBlobFormats.Spaced))
                        {
                            sb.Append(" ");
                            x += 1L;
                        }
                    }

                    if (Conversions.ToBoolean(format & StringBlobFormats.Quoted))
                    {
                        sb.Append("\"");
                        x += 1L;
                    }

                    lpstr._ptr = (IntPtr)_index[i].ToInt64();
                    sb.Append(lpstr.Text);
                    x += lpstr.Length;
                    if (Conversions.ToBoolean(format & StringBlobFormats.Quoted))
                    {
                        sb.Append("\"");
                        x += 1L;
                    }

                    if (Conversions.ToBoolean(format & StringBlobFormats.CrLf))
                    {
                        sb.Append(Constants.vbCr);
                        x += 1L;
                        sb.Append(Constants.vbLf);
                        x += 1L;
                    }
                }

                GC.SuppressFinalize(lpstr);
            }

            return(sb.ToString());
        }