Skip to content

Commit

Permalink
Unique names for GlobalizationNative exports
Browse files Browse the repository at this point in the history
For consistency and to enable eventual sharing of the same code with CoreRT, I have changed the naming convention for System.Globalization.Native exports to match dotnet/corefx#4818.
  • Loading branch information
jkotas committed Jan 29, 2016
1 parent d4eccd4 commit 3be5028
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 191 deletions.
21 changes: 12 additions & 9 deletions src/corefx/System.Globalization.Native/calendarData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ GetCalendars
Returns the list of CalendarIds that are available for the specified locale.
*/
extern "C" int32_t GetCalendars(const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity)
extern "C" int32_t GlobalizationNative_GetCalendars(
const UChar* localeName, CalendarId* calendars, int32_t calendarsCapacity)
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
Expand Down Expand Up @@ -285,7 +286,7 @@ GetCalendarInfo
Gets a single string of calendar information by filling the result parameter
with the requested value.
*/
extern "C" CalendarDataResult GetCalendarInfo(
extern "C" CalendarDataResult GlobalizationNative_GetCalendarInfo(
const UChar* localeName, CalendarId calendarId, CalendarDataType dataType, UChar* result, int32_t resultCapacity)
{
UErrorCode err = U_ZERO_ERROR;
Expand Down Expand Up @@ -539,11 +540,12 @@ Allows for a collection of calendar string data to be retrieved by invoking
the callback for each value in the collection.
The context parameter is passed through to the callback along with each string.
*/
extern "C" int32_t EnumCalendarInfo(EnumCalendarInfoCallback callback,
const UChar* localeName,
CalendarId calendarId,
CalendarDataType dataType,
const void* context)
extern "C" int32_t GlobalizationNative_EnumCalendarInfo(
EnumCalendarInfoCallback callback,
const UChar* localeName,
CalendarId calendarId,
CalendarDataType dataType,
const void* context)
{
UErrorCode err = U_ZERO_ERROR;
char locale[ULOC_FULLNAME_CAPACITY];
Expand Down Expand Up @@ -602,7 +604,7 @@ GetLatestJapaneseEra
Gets the latest era in the Japanese calendar.
*/
extern "C" int32_t GetLatestJapaneseEra()
extern "C" int32_t GlobalizationNative_GetLatestJapaneseEra()
{
UErrorCode err = U_ZERO_ERROR;
UCalendar* pCal = ucal_open(nullptr, 0, JAPANESE_LOCALE_AND_CALENDAR, UCAL_TRADITIONAL, &err);
Expand All @@ -622,7 +624,8 @@ GetJapaneseEraInfo
Gets the starting Gregorian date of the specified Japanese Era.
*/
extern "C" int32_t GetJapaneseEraStartDate(int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay)
extern "C" int32_t GlobalizationNative_GetJapaneseEraStartDate(
int32_t era, int32_t* startYear, int32_t* startMonth, int32_t* startDay)
{
*startYear = -1;
*startMonth = -1;
Expand Down
199 changes: 95 additions & 104 deletions src/corefx/System.Globalization.Native/casing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,43 @@ ChangeCase
Performs upper or lower casing of a string into a new buffer.
No special casing is performed beyond that provided by ICU.
*/
extern "C" void ChangeCase(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper)
extern "C" void GlobalizationNative_ChangeCase(
const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper)
{
// Iterate through the string, decoding the next one or two UTF-16 code units
// into a codepoint and updating srcIdx to point to the next UTF-16 code unit
// to decode. Then upper or lower case it, write dstCodepoint into lpDst at
// offset dstIdx, and update dstIdx.
// Iterate through the string, decoding the next one or two UTF-16 code units
// into a codepoint and updating srcIdx to point to the next UTF-16 code unit
// to decode. Then upper or lower case it, write dstCodepoint into lpDst at
// offset dstIdx, and update dstIdx.

// (The loop here has been manually cloned for each of the four cases, rather
// than having a single loop that internally branched based on bToUpper as the
// compiler wasn't doing that optimization, and it results in an ~15-20% perf
// improvement on longer strings.)
// (The loop here has been manually cloned for each of the four cases, rather
// than having a single loop that internally branched based on bToUpper as the
// compiler wasn't doing that optimization, and it results in an ~15-20% perf
// improvement on longer strings.)

UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;
UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = u_toupper(srcCodepoint);
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = u_tolower(srcCodepoint);
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = u_toupper(srcCodepoint);
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = u_tolower(srcCodepoint);
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
}

/*
Expand All @@ -65,44 +62,41 @@ Performs upper or lower casing of a string into a new buffer.
Special casing is performed to ensure that invariant casing
matches that of Windows in certain situations, e.g. Turkish i's.
*/
extern "C" void ChangeCaseInvariant(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper)
extern "C" void GlobalizationNative_ChangeCaseInvariant(
const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper)
{
// See algorithmic comment in ChangeCase.
// See algorithmic comment in ChangeCase.

UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;
UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
// On Windows with InvariantCulture, the LATIN SMALL LETTER DOTLESS I (U+0131)
// capitalizes to itself, whereas with ICU it capitalizes to LATIN CAPITAL LETTER I (U+0049).
// We special case it to match the Windows invariant behavior.
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0131) ? (UChar32)0x0131 : u_toupper(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
// On Windows with InvariantCulture, the LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130)
// lower cases to itself, whereas with ICU it lower cases to LATIN SMALL LETTER I (U+0069).
// We special case it to match the Windows invariant behavior.
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0130) ? (UChar32)0x0130 : u_tolower(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
// On Windows with InvariantCulture, the LATIN SMALL LETTER DOTLESS I (U+0131)
// capitalizes to itself, whereas with ICU it capitalizes to LATIN CAPITAL LETTER I (U+0049).
// We special case it to match the Windows invariant behavior.
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0131) ? (UChar32)0x0131 : u_toupper(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
// On Windows with InvariantCulture, the LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130)
// lower cases to itself, whereas with ICU it lower cases to LATIN SMALL LETTER I (U+0069).
// We special case it to match the Windows invariant behavior.
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0130) ? (UChar32)0x0130 : u_tolower(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
}

/*
Expand All @@ -112,40 +106,37 @@ ChangeCaseTurkish
Performs upper or lower casing of a string into a new buffer, performing special
casing for Turkish.
*/
extern "C" void ChangeCaseTurkish(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper)
extern "C" void GlobalizationNative_ChangeCaseTurkish(
const UChar* lpSrc, int32_t cwSrcLength, UChar* lpDst, int32_t cwDstLength, int32_t bToUpper)
{
// See algorithmic comment in ChangeCase.
// See algorithmic comment in ChangeCase.

UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;
UBool isError = FALSE;
int32_t srcIdx = 0, dstIdx = 0;
UChar32 srcCodepoint, dstCodepoint;

if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
// In turkish casing, LATIN SMALL LETTER I (U+0069) upper cases to LATIN
// CAPITAL LETTER I WITH DOT ABOVE (U+0130).
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0069) ? (UChar32)0x0130 : u_toupper(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
// In turkish casing, LATIN CAPITAL LETTER I (U+0049) lower cases to
// LATIN SMALL LETTER DOTLESS I (U+0131).
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0049) ? (UChar32)0x0131 : u_tolower(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
if (bToUpper)
{
while (srcIdx < cwSrcLength)
{
// In turkish casing, LATIN SMALL LETTER I (U+0069) upper cases to LATIN
// CAPITAL LETTER I WITH DOT ABOVE (U+0130).
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0069) ? (UChar32)0x0130 : u_toupper(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
else
{
while (srcIdx < cwSrcLength)
{
// In turkish casing, LATIN CAPITAL LETTER I (U+0049) lower cases to
// LATIN SMALL LETTER DOTLESS I (U+0131).
U16_NEXT(lpSrc, srcIdx, cwSrcLength, srcCodepoint);
dstCodepoint = ((srcCodepoint == (UChar32)0x0049) ? (UChar32)0x0131 : u_tolower(srcCodepoint));
U16_APPEND(lpDst, dstIdx, cwDstLength, dstCodepoint, isError);
assert(isError == FALSE && srcIdx == dstIdx);
}
}
}
Loading

0 comments on commit 3be5028

Please sign in to comment.