Author: bnickel
Date: 2007-05-03 13:53:25 -0400 (Thu, 03 May 2007)
New Revision: 76632
Modified:
tags/taglib-sharp-1-1-final/src/TagLib/ByteVector.cs
Log:
Fixed ByteVector.FromString and ByteVector.FromStrings
Modified: tags/taglib-sharp-1-1-final/src/TagLib/ByteVector.cs
===================================================================
--- tags/taglib-sharp-1-1-final/src/TagLib/ByteVector.cs 2007-05-03
17:37:16 UTC (rev 76631)
+++ tags/taglib-sharp-1-1-final/src/TagLib/ByteVector.cs 2007-05-03
17:53:25 UTC (rev 76632)
@@ -447,7 +447,7 @@
public string ToString(StringType type, int offset)
{
- ByteVector bom = type == StringType.UTF16 ? Mid(offset, 2) : null;
+ ByteVector bom = type == StringType.UTF16 && data.Count > 1 ?
Mid(offset, 2) : null;
string s = StringTypeToEncoding(type, bom).GetString(Data, offset,
Count - offset);
if(s.Length != 0 && (s[0] == 0xfffe || s[0] == 0xfeff)) { // UTF16
BOM
@@ -469,23 +469,50 @@
public string[] ToStrings (StringType type, int offset)
{
- return ToStrings (type, offset, 0);
+ return ToStrings (type, offset, int.MaxValue);
}
public string[] ToStrings (StringType type, int offset, int count)
{
- string[] split = count <= 0 ? ToString (type, offset).Split ('\0')
:
- ToString (type, offset).Split (new char[] {'\0'}, count);
+ int chunk = 0;
+ int pos = offset;
- for (int i = 0; i < split.Length; i++)
+ StringList l = new StringList ();
+ ByteVector separator = TagLib.Id3v2.Frame.TextDelimiter (type);
+ int align = separator.Count;
+
+ while (chunk < count && pos < Count)
{
- string s = split [i];
- if (s.Length != 0 && (s[0] == 0xfffe || s[0] == 0xfeff))
- { // UTF16 BOM
- split[i] = s.Substring (1);
- }
+ int start = pos;
+
+ if (chunk + 1 == count)
+ pos = offset + count;
+ else
+ {
+ pos = Find (separator, start, align);
+
+ if (pos < 0)
+ pos = Count;
+ }
+
+ int length = pos - start;
+
+ if (length == 0)
+ l.Add (string.Empty);
+ else
+ {
+ string s = Mid (start, length).ToString (type);
+ if (s.Length != 0 && (s[0] == 0xfffe || s[0] == 0xfeff))
+ { // UTF16 BOM
+ s = s.Substring (1);
+ }
+
+ l.Add (s);
+ }
+
+ pos += 2;
}
- return split;
+ return l.ToArray ();
}
#endregion
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches