// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright ( C ) 1999 - 2010 , International Business Machines
* Corporation and others . All Rights Reserved .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* file name : uinvchar . c
* encoding : UTF - 8
* tab size : 8 ( not used )
* indentation : 2
*
* created on : 2004 sep14
* created by : Markus W . Scherer
*
* Functions for handling invariant characters , moved here from putil . c
* for better modularization .
*/
#include "unicode/utypes.h"
#include "unicode/ustring.h"
#include "udataswp.h"
#include "cstring.h"
#include "cmemory.h"
#include "uassert.h"
#include "uinvchar.h"
/* invariant-character handling --------------------------------------------- */
/*
* These maps for ASCII to / from EBCDIC map invariant characters ( see utypes . h )
* appropriately for most EBCDIC codepages .
*
* They currently also map most other ASCII graphic characters ,
* appropriately for codepages 37 and 1047 .
* Exceptions : The characters for [ ] ^ have different codes in 37 & 1047 .
* Both versions are mapped to ASCII .
*
* ASCII 37 1047
* [ 5 B BA AD
* ] 5 D BB BD
* ^ 5 E B0 5 F
*
* There are no mappings for variant characters from Unicode to EBCDIC .
*
* Currently , C0 control codes are also included in these maps .
* Exceptions : S / 390 Open Edition swaps LF and NEL codes compared with other
* EBCDIC platforms ; both codes ( 15 and 25 ) are mapped to ASCII LF ( 0 A ) ,
* but there is no mapping for ASCII LF back to EBCDIC .
*
* ASCII EBCDIC S / 390 - OE
* LF 0 A 25 15
* NEL 85 15 25
*
* The maps below explicitly exclude the variant
* control and graphical characters that are in ASCII - based
* codepages at 0 x80 and above .
* " No mapping " is expressed by mapping to a 00 byte .
*
* These tables do not establish a converter or a codepage .
*/
static const uint8_t asciiFromEbcdic[
256 ]={
0 x00,
0 x01,
0 x02,
0 x03,
0 x00,
0 x09,
0 x00,
0 x7f,
0 x00,
0 x00,
0 x00,
0 x0b,
0 x0c,
0 x0d,
0 x0e,
0 x0f,
0 x10,
0 x11,
0 x12,
0 x13,
0 x00,
0 x0a,
0 x08,
0 x00,
0 x18,
0 x19,
0 x00,
0 x00,
0 x1c,
0 x1d,
0 x1e,
0 x1f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x0a,
0 x17,
0 x1b,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x05,
0 x06,
0 x07,
0 x00,
0 x00,
0 x16,
0 x00,
0 x00,
0 x00,
0 x00,
0 x04,
0 x00,
0 x00,
0 x00,
0 x00,
0 x14,
0 x15,
0 x00,
0 x1a,
0 x20,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x2e,
0 x3c,
0 x28,
0 x2b,
0 x7c,
0 x26,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x21,
0 x24,
0 x2a,
0 x29,
0 x3b,
0 x5e,
0 x2d,
0 x2f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x2c,
0 x25,
0 x5f,
0 x3e,
0 x3f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x60,
0 x3a,
0 x23,
0 x40,
0 x27,
0 x3d,
0 x22,
0 x00,
0 x61,
0 x62,
0 x63,
0 x64,
0 x65,
0 x66,
0 x67,
0 x68,
0 x69,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x6a,
0 x6b,
0 x6c,
0 x6d,
0 x6e,
0 x6f,
0 x70,
0 x71,
0 x72,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x7e,
0 x73,
0 x74,
0 x75,
0 x76,
0 x77,
0 x78,
0 x79,
0 x7a,
0 x00,
0 x00,
0 x00,
0 x5b,
0 x00,
0 x00,
0 x5e,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x5b,
0 x5d,
0 x00,
0 x5d,
0 x00,
0 x00,
0 x7b,
0 x41,
0 x42,
0 x43,
0 x44,
0 x45,
0 x46,
0 x47,
0 x48,
0 x49,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x7d,
0 x4a,
0 x4b,
0 x4c,
0 x4d,
0 x4e,
0 x4f,
0 x50,
0 x51,
0 x52,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x5c,
0 x00,
0 x53,
0 x54,
0 x55,
0 x56,
0 x57,
0 x58,
0 x59,
0 x5a,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x30,
0 x31,
0 x32,
0 x33,
0 x34,
0 x35,
0 x36,
0 x37,
0 x38,
0 x39,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00
};
static const uint8_t ebcdicFromAscii[
256 ]={
0 x00,
0 x01,
0 x02,
0 x03,
0 x37,
0 x2d,
0 x2e,
0 x2f,
0 x16,
0 x05,
0 x00,
0 x0b,
0 x0c,
0 x0d,
0 x0e,
0 x0f,
0 x10,
0 x11,
0 x12,
0 x13,
0 x3c,
0 x3d,
0 x32,
0 x26,
0 x18,
0 x19,
0 x3f,
0 x27,
0 x1c,
0 x1d,
0 x1e,
0 x1f,
0 x40,
0 x00,
0 x7f,
0 x00,
0 x00,
0 x6c,
0 x50,
0 x7d,
0 x4d,
0 x5d,
0 x5c,
0 x4e,
0 x6b,
0 x60,
0 x4b,
0 x61,
0 xf0,
0 xf1,
0 xf2,
0 xf3,
0 xf4,
0 xf5,
0 xf6,
0 xf7,
0 xf8,
0 xf9,
0 x7a,
0 x5e,
0 x4c,
0 x7e,
0 x6e,
0 x6f,
0 x00,
0 xc1,
0 xc2,
0 xc3,
0 xc4,
0 xc5,
0 xc6,
0 xc7,
0 xc8,
0 xc9,
0 xd1,
0 xd2,
0 xd3,
0 xd4,
0 xd5,
0 xd6,
0 xd7,
0 xd8,
0 xd9,
0 xe2,
0 xe3,
0 xe4,
0 xe5,
0 xe6,
0 xe7,
0 xe8,
0 xe9,
0 x00,
0 x00,
0 x00,
0 x00,
0 x6d,
0 x00,
0 x81,
0 x82,
0 x83,
0 x84,
0 x85,
0 x86,
0 x87,
0 x88,
0 x89,
0 x91,
0 x92,
0 x93,
0 x94,
0 x95,
0 x96,
0 x97,
0 x98,
0 x99,
0 xa2,
0 xa3,
0 xa4,
0 xa5,
0 xa6,
0 xa7,
0 xa8,
0 xa9,
0 x00,
0 x00,
0 x00,
0 x00,
0 x07,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0 ,
0
};
/* Same as asciiFromEbcdic[] except maps all letters to lowercase. */
static const uint8_t lowercaseAsciiFromEbcdic[
256 ]={
0 x00,
0 x01,
0 x02,
0 x03,
0 x00,
0 x09,
0 x00,
0 x7f,
0 x00,
0 x00,
0 x00,
0 x0b,
0 x0c,
0 x0d,
0 x0e,
0 x0f,
0 x10,
0 x11,
0 x12,
0 x13,
0 x00,
0 x0a,
0 x08,
0 x00,
0 x18,
0 x19,
0 x00,
0 x00,
0 x1c,
0 x1d,
0 x1e,
0 x1f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x0a,
0 x17,
0 x1b,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x05,
0 x06,
0 x07,
0 x00,
0 x00,
0 x16,
0 x00,
0 x00,
0 x00,
0 x00,
0 x04,
0 x00,
0 x00,
0 x00,
0 x00,
0 x14,
0 x15,
0 x00,
0 x1a,
0 x20,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x2e,
0 x3c,
0 x28,
0 x2b,
0 x7c,
0 x26,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x21,
0 x24,
0 x2a,
0 x29,
0 x3b,
0 x5e,
0 x2d,
0 x2f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x2c,
0 x25,
0 x5f,
0 x3e,
0 x3f,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x60,
0 x3a,
0 x23,
0 x40,
0 x27,
0 x3d,
0 x22,
0 x00,
0 x61,
0 x62,
0 x63,
0 x64,
0 x65,
0 x66,
0 x67,
0 x68,
0 x69,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x6a,
0 x6b,
0 x6c,
0 x6d,
0 x6e,
0 x6f,
0 x70,
0 x71,
0 x72,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x7e,
0 x73,
0 x74,
0 x75,
0 x76,
0 x77,
0 x78,
0 x79,
0 x7a,
0 x00,
0 x00,
0 x00,
0 x5b,
0 x00,
0 x00,
0 x5e,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x5b,
0 x5d,
0 x00,
0 x5d,
0 x00,
0 x00,
0 x7b,
0 x61,
0 x62,
0 x63,
0 x64,
0 x65,
0 x66,
0 x67,
0 x68,
0 x69,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x7d,
0 x6a,
0 x6b,
0 x6c,
0 x6d,
0 x6e,
0 x6f,
0 x70,
0 x71,
0 x72,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x7c,
0 x00,
0 x73,
0 x74,
0 x75,
0 x76,
0 x77,
0 x78,
0 x79,
0 x7a,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x30,
0 x31,
0 x32,
0 x33,
0 x34,
0 x35,
0 x36,
0 x37,
0 x38,
0 x39,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00,
0 x00
};
/*
* Bit sets indicating which characters of the ASCII repertoire
* ( by ASCII / Unicode code ) are " invariant " .
* See utypes . h for more details .
*
* As invariant are considered the characters of the ASCII repertoire except
* for the following :
* 21 ' ! ' < exclamation mark >
* 23 ' # ' < number sign >
* 24 ' $ ' < dollar sign >
*
* 40 ' @ ' < commercial at >
*
* 5 b ' [ ' < left bracket >
* 5 c ' \ ' < backslash >
* 5 d ' ] ' < right bracket >
* 5 e ' ^ ' < circumflex >
*
* 60 ' ` ' < grave accent >
*
* 7 b ' { ' < left brace >
* 7 c ' | ' < vertical line >
* 7 d ' } ' < right brace >
* 7 e ' ~ ' < tilde >
*/
static const uint32_t invariantChars[
4 ]={
0 xfffffbff,
/* 00..1f but not 0a */
0 xffffffe5,
/* 20..3f but not 21 23 24 */
0 x87fffffe,
/* 40..5f but not 40 5b..5e */
0 x87fffffe
/* 60..7f but not 60 7b..7e */
};
/*
* test unsigned types ( or values known to be non - negative ) for invariant characters ,
* tests ASCII - family character values
*/
#define UCHAR_IS_INVARIANT(c) (((c)<=
0 x7f) && (invariantChars[(c)>>
5 ]&((uint32_t)
1 <<((c)&
0 x1f)))!=
0 )
/* test signed types for invariant characters, adds test for positive values */
#define SCHAR_IS_INVARIANT(c) ((
0 <=(c)) && UCHAR_IS_INVARIANT(c))
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
#define CHAR_TO_UCHAR(c) c
#define UCHAR_TO_CHAR(c) c
#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
#define CHAR_TO_UCHAR(u) asciiFromEbcdic[u]
#define UCHAR_TO_CHAR(u) ebcdicFromAscii[u]
#else
# error U_CHARSET_FAMILY is
not valid
#endif
U_CAPI
void U_EXPORT2
u_charsToUChars(
const char *cs, char16_t *us, int32_t length) {
char16_t u;
uint8_t c;
/*
* Allow the entire ASCII repertoire to be mapped _ to_ Unicode .
* For EBCDIC systems , this works for characters with codes from
* codepages 37 and 1047 or compatible .
*/
while (length>
0 ) {
c=(uint8_t)(*cs++);
u=(char16_t)CHAR_TO_UCHAR(c);
U_ASSERT((u!=
0 || c==
0 ));
/* only invariant chars converted? */
*us++=u;
--length;
}
}
U_CAPI
void U_EXPORT2
u_UCharsToChars(
const char16_t *us,
char *cs, int32_t length) {
char16_t u;
while (length>
0 ) {
u=*us++;
if (!UCHAR_IS_INVARIANT(u)) {
U_ASSERT(
false );
/* Variant characters were used. These are not portable in ICU. */
u=
0 ;
}
*cs++=(
char )UCHAR_TO_CHAR(u);
--length;
}
}
U_CAPI UBool U_EXPORT2
uprv_isInvariantString(
const char *s, int32_t length) {
uint8_t c;
for (;;) {
if (length<
0 ) {
/* NUL-terminated */
c=(uint8_t)*s++;
if (c==
0 ) {
break ;
}
}
else {
/* count length */
if (length==
0 ) {
break ;
}
--length;
c=(uint8_t)*s++;
if (c==
0 ) {
continue ;
/* NUL is invariant */
}
}
/* c!=0 now, one branch below checks c==0 for variant characters */
/*
* no assertions here because these functions are legitimately called
* for strings with variant characters
*/
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
if (!UCHAR_IS_INVARIANT(c)) {
return false ;
/* found a variant char */
}
#elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
c=CHAR_TO_UCHAR(c);
if (c==
0 || !UCHAR_IS_INVARIANT(c)) {
return false ;
/* found a variant char */
}
#else
# error U_CHARSET_FAMILY is
not valid
#endif
}
return true;
}
U_CAPI UBool U_EXPORT2
uprv_isInvariantUString(
const char16_t *s, int32_t length) {
char16_t c;
for (;;) {
if (length<
0 ) {
/* NUL-terminated */
c=*s++;
if (c==
0 ) {
break ;
}
}
else {
/* count length */
if (length==
0 ) {
break ;
}
--length;
c=*s++;
}
/*
* no assertions here because these functions are legitimately called
* for strings with variant characters
*/
if (!UCHAR_IS_INVARIANT(c)) {
return false ;
/* found a variant char */
}
}
return true;
}
/* UDataSwapFn implementations used in udataswp.c ------- */
/* convert ASCII to EBCDIC and verify that all characters are invariant */
U_CAPI int32_t U_EXPORT2
uprv_ebcdicFromAscii(
const UDataSwapper *ds,
const void *inData, int32_t length,
void *outData,
UErrorCode *pErrorCode) {
const uint8_t *s;
uint8_t *t;
uint8_t c;
int32_t count;
if (pErrorCode==nullptr || U_FAILURE(*pErrorCode)) {
return 0 ;
}
if (ds==nullptr || inData==nullptr || length<
0 || (length>
0 && outData==nullptr)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0 ;
}
/* setup and swapping */
s=(
const uint8_t *)inData;
t=(uint8_t *)outData;
count=length;
while (count>
0 ) {
c=*s++;
if (!UCHAR_IS_INVARIANT(c)) {
udata_printError(ds,
"uprv_ebcdicFromAscii() string[%d] contains a variant character in position %d\n" ,
length, length-count);
*pErrorCode=U_INVALID_CHAR_FOUND;
return 0 ;
}
*t++=ebcdicFromAscii[c];
--count;
}
return length;
}
/* this function only checks and copies ASCII strings without conversion */
U_CFUNC int32_t
uprv_copyAscii(
const UDataSwapper *ds,
const void *inData, int32_t length,
void *outData,
UErrorCode *pErrorCode) {
const uint8_t *s;
uint8_t c;
int32_t count;
if (pErrorCode==nullptr || U_FAILURE(*pErrorCode)) {
return 0 ;
}
if (ds==nullptr || inData==nullptr || length<
0 || (length>
0 && outData==nullptr)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0 ;
}
/* setup and checking */
s=(
const uint8_t *)inData;
count=length;
while (count>
0 ) {
c=*s++;
if (!UCHAR_IS_INVARIANT(c)) {
udata_printError(ds,
"uprv_copyFromAscii() string[%d] contains a variant character in position %d\n" ,
length, length-count);
*pErrorCode=U_INVALID_CHAR_FOUND;
return 0 ;
}
--count;
}
if (length>
0 && inData!=outData) {
uprv_memcpy(outData, inData, length);
}
return length;
}
/* convert EBCDIC to ASCII and verify that all characters are invariant */
U_CFUNC int32_t
uprv_asciiFromEbcdic(
const UDataSwapper *ds,
const void *inData, int32_t length,
void *outData,
UErrorCode *pErrorCode) {
const uint8_t *s;
uint8_t *t;
uint8_t c;
int32_t count;
if (pErrorCode==nullptr || U_FAILURE(*pErrorCode)) {
return 0 ;
}
if (ds==nullptr || inData==nullptr || length<
0 || (length>
0 && outData==nullptr)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0 ;
}
/* setup and swapping */
s=(
const uint8_t *)inData;
t=(uint8_t *)outData;
count=length;
while (count>
0 ) {
c=*s++;
if (c!=
0 && ((c=asciiFromEbcdic[c])==
0 || !UCHAR_IS_INVARIANT(c))) {
udata_printError(ds,
"uprv_asciiFromEbcdic() string[%d] contains a variant character in position %d\n" ,
length, length-count);
*pErrorCode=U_INVALID_CHAR_FOUND;
return 0 ;
}
*t++=c;
--count;
}
return length;
}
/* this function only checks and copies EBCDIC strings without conversion */
U_CFUNC int32_t
uprv_copyEbcdic(
const UDataSwapper *ds,
const void *inData, int32_t length,
void *outData,
UErrorCode *pErrorCode) {
const uint8_t *s;
uint8_t c;
int32_t count;
if (pErrorCode==nullptr || U_FAILURE(*pErrorCode)) {
return 0 ;
}
if (ds==nullptr || inData==nullptr || length<
0 || (length>
0 && outData==nullptr)) {
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0 ;
}
/* setup and checking */
s=(
const uint8_t *)inData;
count=length;
while (count>
0 ) {
c=*s++;
if (c!=
0 && ((c=asciiFromEbcdic[c])==
0 || !UCHAR_IS_INVARIANT(c))) {
udata_printError(ds,
"uprv_copyEbcdic() string[%] contains a variant character in position %d\n" ,
length, length-count);
*pErrorCode=U_INVALID_CHAR_FOUND;
return 0 ;
}
--count;
}
if (length>
0 && inData!=outData) {
uprv_memcpy(outData, inData, length);
}
return length;
}
U_CAPI UBool
uprv_isEbcdicAtSign(
char c) {
static const uint8_t ebcdicAtSigns[] = {
0 x7C,
0 x44,
0 x66,
0 x80,
0 xAC,
0 xAE,
0 xAF,
0 xB5,
0 xEC,
0 xEF,
0 x00 };
return c !=
0 && uprv_strchr((
const char *)ebcdicAtSigns, c) != nullptr;
}
/* compare invariant strings; variant characters compare less than others and unlike each other */
U_CFUNC int32_t
uprv_compareInvAscii(
const UDataSwapper *ds,
const char *outString, int32_t outLength,
const char16_t *localString, int32_t localLength) {
(
void )ds;
int32_t minLength;
UChar32 c1, c2;
uint8_t c;
if (outString==nullptr || outLength<-
1 || localString==nullptr || localLength<-
1 ) {
return 0 ;
}
if (outLength<
0 ) {
outLength=(int32_t)uprv_strlen(outString);
}
if (localLength<
0 ) {
localLength=u_strlen(localString);
}
minLength= outLength<localLength ? outLength : localLength;
while (minLength>
0 ) {
c=(uint8_t)*outString++;
if (UCHAR_IS_INVARIANT(c)) {
c1=c;
}
else {
c1=-
1 ;
}
c2=*localString++;
if (!UCHAR_IS_INVARIANT(c2)) {
c2=-
2 ;
}
if ((c1-=c2)!=
0 ) {
return c1;
}
--minLength;
}
/* strings start with same prefix, compare lengths */
return outLength-localLength;
}
U_CFUNC int32_t
uprv_compareInvEbcdic(
const UDataSwapper *ds,
const char *outString, int32_t outLength,
const char16_t *localString, int32_t localLength) {
(
void )ds;
int32_t minLength;
UChar32 c1, c2;
uint8_t c;
if (outString==nullptr || outLength<-
1 || localString==nullptr || localLength<-
1 ) {
return 0 ;
}
if (outLength<
0 ) {
outLength=(int32_t)uprv_strlen(outString);
}
if (localLength<
0 ) {
localLength=u_strlen(localString);
}
minLength= outLength<localLength ? outLength : localLength;
while (minLength>
0 ) {
c=(uint8_t)*outString++;
if (c==
0 ) {
c1=
0 ;
}
else if ((c1=asciiFromEbcdic[c])!=
0 && UCHAR_IS_INVARIANT(c1)) {
/* c1 is set */
}
else {
c1=-
1 ;
}
c2=*localString++;
if (!UCHAR_IS_INVARIANT(c2)) {
c2=-
2 ;
}
if ((c1-=c2)!=
0 ) {
return c1;
}
--minLength;
}
/* strings start with same prefix, compare lengths */
return outLength-localLength;
}
U_CAPI int32_t U_EXPORT2
uprv_compareInvEbcdicAsAscii(
const char *s1,
const char *s2) {
int32_t c1, c2;
for (;; ++s1, ++s2) {
c1=(uint8_t)*s1;
c2=(uint8_t)*s2;
if (c1!=c2) {
if (c1!=
0 && ((c1=asciiFromEbcdic[c1])==
0 || !UCHAR_IS_INVARIANT(c1))) {
c1=-(int32_t)(uint8_t)*s1;
}
if (c2!=
0 && ((c2=asciiFromEbcdic[c2])==
0 || !UCHAR_IS_INVARIANT(c2))) {
c2=-(int32_t)(uint8_t)*s2;
}
return c1-c2;
}
else if (c1==
0 ) {
return 0 ;
}
}
}
U_CAPI
char U_EXPORT2
uprv_ebcdicToAscii(
char c) {
return (
char )asciiFromEbcdic[(uint8_t)c];
}
U_CAPI
char U_EXPORT2
uprv_ebcdicToLowercaseAscii(
char c) {
return (
char )lowercaseAsciiFromEbcdic[(uint8_t)c];
}
U_CAPI uint8_t* U_EXPORT2
uprv_aestrncpy(uint8_t *dst,
const uint8_t *src, int32_t n)
{
uint8_t *orig_dst = dst;
if (n==-
1 ) {
n = static_cast<int32_t>(uprv_strlen((
const char *)src)+
1 );
/* copy NUL */
}
/* copy non-null */
while (*src && n>
0 ) {
*(dst++) = asciiFromEbcdic[*(src++)];
n--;
}
/* pad */
while (n>
0 ) {
*(dst++) =
0 ;
n--;
}
return orig_dst;
}
U_CAPI uint8_t* U_EXPORT2
uprv_eastrncpy(uint8_t *dst,
const uint8_t *src, int32_t n)
{
uint8_t *orig_dst = dst;
if (n==-
1 ) {
n = static_cast<int32_t>(uprv_strlen((
const char *)src)+
1 );
/* copy NUL */
}
/* copy non-null */
while (*src && n>
0 ) {
char ch = ebcdicFromAscii[*(src++)];
if (ch ==
0 ) {
ch = ebcdicFromAscii[
0 x3f];
/* questionmark (subchar) */
}
*(dst++) = ch;
n--;
}
/* pad */
while (n>
0 ) {
*(dst++) =
0 ;
n--;
}
return orig_dst;
}
Messung V0.5 in Prozent C=89 H=91 G=89
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-08-26)
¤
*© Formatika GbR, Deutschland