/* * 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 * [ 5B BA AD * ] 5D BB BD * ^ 5E B0 5F * * 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 (0A), * but there is no mapping for ASCII LF back to EBCDIC. * * ASCII EBCDIC S/390-OE * LF 0A 25 15 * NEL 85 15 25 * * The maps below explicitly exclude the variant * control and graphical characters that are in ASCII-based * codepages at 0x80 and above. * "No mapping" is expressed by mapping to a 00 byte. * * These tables do not establish a converter or a codepage.
*/
/* * 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> * * 5b '[' <left bracket> * 5c '\' <backslash> * 5d ']' <right bracket> * 5e '^' <circumflex> * * 60 '`' <grave accent> * * 7b '{' <left brace> * 7c '|' <vertical line> * 7d '}' <right brace> * 7e '~' <tilde>
*/ staticconst uint32_t invariantChars[4]={ 0xfffffbff, /* 00..1f but not 0a */ 0xffffffe5, /* 20..3f but not 21 23 24 */ 0x87fffffe, /* 40..5f but not 40 5b..5e */ 0x87fffffe /* 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)<=0x7f) && (invariantChars[(c)>>5]&((uint32_t)1<<((c)&0x1f)))!=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
/* * 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;
}
}
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;
}
}
/* * 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)) { returnfalse; /* found a variant char */
} #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY
c=CHAR_TO_UCHAR(c); if(c==0 || !UCHAR_IS_INVARIANT(c)) { returnfalse; /* found a variant char */
} #else # error U_CHARSET_FAMILY is not valid #endif
} returntrue;
}
/* * no assertions here because these functions are legitimately called * for strings with variant characters
*/ if(!UCHAR_IS_INVARIANT(c)) { returnfalse; /* found a variant char */
}
} returntrue;
}
/* 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, constvoid *inData, int32_t length, void *outData,
UErrorCode *pErrorCode) { const uint8_t *s;
uint8_t *t;
uint8_t c;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.