[Mono-bugs] [Bug 463141] New: AddUserString broken.
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Wed Dec 31 14:44:48 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=463141
Summary: AddUserString broken.
Product: Mono: Class Libraries
Version: 2.2.x
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Cecil
AssignedTo: jbevain at novell.com
ReportedBy: high6 at live.com
QAContact: mono-bugs at lists.ximian.com
Found By: ---
You fixed this problem in ReadStringAt but not AddUserString.
byte[] us = Encoding.Unicode.GetBytes(str);
Encoding.Unicode does not function properly and breaks true unicode strings
sometimes.
I whipped up a fix that I am using (You can of course do a better neater fix).
byte[] Str2Bytes(string str)
{
byte[] ret = new byte[str.Length * 2];
int len = ret.Length;
for (int i = 0, j = 0; i < len; i += 2, j++)
{
ret[i] = (byte)(str[j] & 0xFF);
ret[i + 1] = (byte)(str[j] >> 8);
}
return ret;
}
public uint AddUserString(string str)
{
if (str == null)
return 0;
if (m_usCache.Contains(str))
return (uint)m_usCache[str];
uint pointer = (uint)m_usWriter.BaseStream.Position;
m_usCache[str] = pointer;
byte[] us = Str2Bytes(str);
Utilities.WriteCompressedInteger(m_usWriter, us.Length + 1);
m_usWriter.Write(us);
m_usWriter.Write((byte)(RequiresSpecialHandling(us) ? 1 : 0));
return pointer;
}
Basically I have it manually create a byte[] from a string instead of using
Encoding.Unicode. Just like in ReadStringAt().
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
More information about the mono-bugs
mailing list