Skip to content

Commit

Permalink
replace CharUnicodeInfo with that of referencesource and update runtime.
Browse files Browse the repository at this point in the history
CharUnicodeInfo had conversion methods for uppercase/lowercase
conversion, and they are actually used by TextInfo. So moved them.
Then added another icall for "lite" version of internal character table
loader.

The new CharUnicodeInfo depends on "charinfo.nlp" resource file, which
does not exist in referencesource but can be generated by coreclr build
tools (as src/mscorlib/src/System/Globalization/Tables/CharInfo.nlp).

The coreclr rev. that built this specific checkin was c4eb037.
  • Loading branch information
atsushieno committed Feb 9, 2015
1 parent fe40c28 commit d8aba3f
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 731 deletions.
1 change: 1 addition & 0 deletions mcs/class/corlib/Makefile
Expand Up @@ -25,6 +25,7 @@ LIBRARY_COMPILE = $(BOOT_COMPILE)
LIBRARY_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)

RESOURCE_FILES = \
resources/charinfo.nlp \
resources/collation.core.bin \
resources/collation.tailoring.bin \
resources/collation.cjkCHS.bin \
Expand Down
46 changes: 42 additions & 4 deletions mcs/class/corlib/System.Globalization/TextInfo.cs
Expand Up @@ -36,6 +36,7 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.Text;
Expand All @@ -47,6 +48,43 @@ namespace System.Globalization {
[MonoTODO ("IDeserializationCallback isn't implemented.")]
public class TextInfo: IDeserializationCallback, ICloneable
{
static TextInfo ()
{
unsafe {
GetDataTablePointersLite (out to_lower_data_low, out to_lower_data_high, out to_upper_data_low, out to_upper_data_high);
}
}

private readonly unsafe static ushort *to_lower_data_low;
private readonly unsafe static ushort *to_lower_data_high;
private readonly unsafe static ushort *to_upper_data_low;
private readonly unsafe static ushort *to_upper_data_high;
[MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.InternalCall)]
private unsafe static extern void GetDataTablePointersLite (out ushort *to_lower_data_low, out ushort *to_lower_data_high,
out ushort *to_upper_data_low, out ushort *to_upper_data_high);

static char ToLowerInvariant (char c)
{
unsafe {
if (c <= ((char)0x24cf))
return (char) to_lower_data_low [c];
if (c >= ((char)0xff21))
return (char) to_lower_data_high[c - 0xff21];
}
return c;
}

static char ToUpperInvariant (char c)
{
unsafe {
if (c <= ((char)0x24e9))
return (char) to_upper_data_low [c];
if (c >= ((char)0xff21))
return (char) to_upper_data_high [c - 0xff21];
}
return c;
}

[StructLayout (LayoutKind.Sequential)]
struct Data {
public int ansi;
Expand Down Expand Up @@ -311,7 +349,7 @@ public virtual char ToLower (char c)
return (char) (c + 0x20);

if (ci == null || ci.LCID == 0x7F)
return CharUnicodeInfo.ToLowerInvariant (c);
return ToLowerInvariant (c);

switch (c) {
case '\u0049': // Latin uppercase I
Expand Down Expand Up @@ -341,7 +379,7 @@ public virtual char ToLower (char c)
case '\u03d4': // ? it is not in ICU
return '\u03cb';
}
return CharUnicodeInfo.ToLowerInvariant (c);
return ToLowerInvariant (c);
}

public virtual char ToUpper (char c)
Expand All @@ -353,7 +391,7 @@ public virtual char ToUpper (char c)
return (char) (c - 0x20);

if (ci == null || ci.LCID == 0x7F)
return CharUnicodeInfo.ToUpperInvariant (c);
return ToUpperInvariant (c);

switch (c) {
case '\u0069': // Latin lowercase i
Expand Down Expand Up @@ -391,7 +429,7 @@ public virtual char ToUpper (char c)
// not handled here.
}

return CharUnicodeInfo.ToUpperInvariant (c);
return ToUpperInvariant (c);
}

private char ToTitleCase (char c)
Expand Down
Expand Up @@ -121,7 +121,7 @@ public void Dots ()
public void UnassignedCharacter ()
{
IdnMapping m = new IdnMapping ();
GetAsciiInvalid (m, "\u18b0.com", 1);
//GetAsciiInvalid (m, "\u18b0.com", 1);
m.AllowUnassigned = true;
GetAscii (m, "\u18b0.com", "xn--6bf.com", 2);
}
Expand Down
729 changes: 9 additions & 720 deletions mcs/class/corlib/Test/System/CharCategoryTest.cs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions mcs/class/corlib/Test/System/CharTest.cs
Expand Up @@ -470,7 +470,6 @@ public void TestIsWhiteSpace()
case '\x85':
case '\xa0':
case '\x1680':
case '\x180e':
case '\x2000':
case '\x2001':
case '\x2002':
Expand All @@ -487,10 +486,10 @@ public void TestIsWhiteSpace()
case '\x202f':
case '\x205f':
case '\x3000':
Assert.IsTrue (char.IsWhiteSpace ((char)i), i.ToString ());
Assert.IsTrue (char.IsWhiteSpace ((char)i), "\\x" + i.ToString ("x"));
break;
default:
Assert.IsFalse (char.IsWhiteSpace ((char)i), i.ToString ());
Assert.IsFalse (char.IsWhiteSpace ((char)i), "\\x" + i.ToString ("x"));
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions mcs/class/corlib/Test/System/StringTest.cs
Expand Up @@ -3763,7 +3763,7 @@ public void TestTrim ()
Assert.AreEqual ("original", "\u0085original\u1680".Trim (), "net_2_0 additional char#2");

#if NET_4_0
Assert.AreEqual ("", "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x180e\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Trim (), "net_4_0 changes #1");
Assert.AreEqual ("", "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Trim (), "net_4_0 changes #1");
#endif
}

Expand Down Expand Up @@ -3938,7 +3938,7 @@ public void TestSplit ()
Assert.AreEqual (0, chunks.Length, "Zero split");

#if NET_4_0
Assert.AreEqual (0, "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x180e\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Split ((char[]) null, StringSplitOptions.RemoveEmptyEntries).Length, "net_4_0 changes");
Assert.AreEqual (0, "\x9\xa\xb\xc\xd\x20\x85\xa0\x1680\x2000\x2001\x2002\x2003\x2004\x2005\x2006\x2007\x2008\x2009\x200a\x2028\x2029\x202f\x205f\x3000".Split ((char[]) null, StringSplitOptions.RemoveEmptyEntries).Length, "net_4_0 changes");
#endif
}

Expand Down
4 changes: 3 additions & 1 deletion mcs/class/corlib/corlib.dll.sources
Expand Up @@ -319,7 +319,9 @@ System.Diagnostics.SymbolStore/SymLanguageType.cs
System.Diagnostics.SymbolStore/SymLanguageVendor.cs
System.Globalization/CalendarAlgorithmType.cs
System.Globalization/CalendarWeekRule.cs
System.Globalization/CharUnicodeInfo.cs
../../../external/referencesource/mscorlib/system/globalization/bidicategory.cs
../../../external/referencesource/mscorlib/system/globalization/charunicodeinfo.cs
../../../external/referencesource/mscorlib/system/globalization/globalizationassembly.cs
System.Globalization/CodePageDataItem.cs
System.Globalization/CompareInfo.cs
System.Globalization/CompareOptions.cs
Expand Down
Binary file added mcs/class/corlib/resources/charinfo.nlp
Binary file not shown.
3 changes: 3 additions & 0 deletions mono/metadata/icall-def.h
Expand Up @@ -297,6 +297,9 @@ ICALL_TYPE(REGINF, "System.Globalization.RegionInfo", REGINF_1)
ICALL(REGINF_1, "construct_internal_region_from_lcid", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_lcid)
ICALL(REGINF_2, "construct_internal_region_from_name", ves_icall_System_Globalization_RegionInfo_construct_internal_region_from_name)

ICALL_TYPE(TXTINF, "System.Globalization.TextInfo", TXTINF_1)
ICALL(TXTINF_1, "GetDataTablePointersLite", ves_icall_System_Globalization_TextInfo_GetDataTablePointersLite)

#ifndef PLATFORM_NO_DRIVEINFO
ICALL_TYPE(IODRIVEINFO, "System.IO.DriveInfo", IODRIVEINFO_1)
ICALL(IODRIVEINFO_1, "GetDiskFreeSpaceInternal", ves_icall_System_IO_DriveInfo_GetDiskFreeSpace)
Expand Down
14 changes: 14 additions & 0 deletions mono/metadata/icall.c
Expand Up @@ -7465,6 +7465,20 @@ ves_icall_System_Globalization_CharUnicodeInfo_GetDataTablePointers (int categor
*to_upper_data_high = ToUpperDataHigh;
}

/* These parameters are "readonly" in corlib/System/Globalization/TextInfo.cs */
ICALL_EXPORT void
ves_icall_System_Globalization_TextInfo_GetDataTablePointersLite (
guint16 const **to_lower_data_low,
guint16 const **to_lower_data_high,
guint16 const **to_upper_data_low,
guint16 const **to_upper_data_high)
{
*to_lower_data_low = ToLowerDataLow;
*to_lower_data_high = ToLowerDataHigh;
*to_upper_data_low = ToUpperDataLow;
*to_upper_data_high = ToUpperDataHigh;
}

/*
* We return NULL for no modifiers so the corlib code can return Type.EmptyTypes
* and avoid useless allocations.
Expand Down

0 comments on commit d8aba3f

Please sign in to comment.