/// <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); }
/// <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); }
/// <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()); }