From e1749f434d98af5d19a6b10dcf8717cb524d2068 Mon Sep 17 00:00:00 2001 From: George Rhoten Date: Thu, 30 Aug 2001 18:25:42 +0000 Subject: [PATCH] ICU-1099 Add const to some static data X-SVN-Rev: 5632 --- icu4c/source/common/scsu.c | 1440 ++++++++++++++++---------------- icu4c/source/common/ubidi.c | 6 +- icu4c/source/common/uhash.c | 2 +- icu4c/source/common/umemstrm.c | 2 +- 4 files changed, 725 insertions(+), 725 deletions(-) diff --git a/icu4c/source/common/scsu.c b/icu4c/source/common/scsu.c index 0b74b06b3c..f3f10deb7f 100644 --- a/icu4c/source/common/scsu.c +++ b/icu4c/source/common/scsu.c @@ -119,7 +119,7 @@ static int32_t scsu_getLRDefinedWindow(const UnicodeCompressor *comp); /* Static tables generated by CompressionTableGenerator */ /** For window offset mapping */ -static int32_t sOffsetTable [] = { +static const int32_t sOffsetTable [] = { 0x0, 0x80, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400, 0x480, 0x500, 0x580, 0x600, 0x680, 0x700, 0x780, 0x800, 0x880, 0x900, 0x980, 0xa00, 0xa80, 0xb00, 0xb80, 0xc00, 0xc80, 0xd00, 0xd80, @@ -151,7 +151,7 @@ static int32_t sOffsetTable [] = { }; /** For quick identification of a byte as a single-byte mode tag */ -static UBool sSingleTagTable [] = { +static const UBool sSingleTagTable [] = { FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, @@ -183,7 +183,7 @@ static UBool sSingleTagTable [] = { }; /** For quick identification of a byte as a unicode mode tag */ -static UBool sUnicodeTagTable [] = { +static const UBool sUnicodeTagTable [] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, @@ -216,7 +216,7 @@ static UBool sUnicodeTagTable [] = { }; /** Static compression window offsets */ -static int32_t sOffsets [] = { +static const int32_t sOffsets [] = { 0x0000, /* for quoting single-byte mode tags*/ 0x0080, /* Latin-1 Supplement*/ 0x0100, /* Latin Extended-A*/ @@ -285,295 +285,295 @@ scsu_compress(UnicodeCompressor *comp, case SINGLEBYTEMODE: while( unicharBuffer < sourceLimit && byteBuffer < targetLimit ) { - /* get current char*/ - curUC = *unicharBuffer++; + /* get current char*/ + curUC = *unicharBuffer++; - /* get next char*/ - if( unicharBuffer < sourceLimit ) - nextUC = *unicharBuffer; - else - nextUC = INVALIDCHAR; + /* get next char*/ + if( unicharBuffer < sourceLimit ) + nextUC = *unicharBuffer; + else + nextUC = INVALIDCHAR; - /* chars less than 0x0080 (excluding tags) go straight in - stream */ - if( curUC < 0x0080 ) { - loByte = curUC; + /* chars less than 0x0080 (excluding tags) go straight in + stream */ + if( curUC < 0x0080 ) { + loByte = curUC; - /* we need to check and make sure we don't - accidentally write a single byte mode tag to - the stream unless it's quoted */ - if(sSingleTagTable[loByte]) { - /* make sure there is enough room to write - both bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* we need to check and make sure we don't + accidentally write a single byte mode tag to + the stream unless it's quoted */ + if(sSingleTagTable[loByte]) { + /* make sure there is enough room to write + both bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - /* since we know the byte is less than 0x80, SQUOTE0 - will use static window 0, or Latin-1*/ - *byteBuffer++ = (uint8_t) SQUOTE0; - } + /* since we know the byte is less than 0x80, SQUOTE0 + will use static window 0, or Latin-1*/ + *byteBuffer++ = (uint8_t) SQUOTE0; + } - *byteBuffer++ = (uint8_t) loByte; - } + *byteBuffer++ = (uint8_t) loByte; + } - /* if the char belongs to current window, convert it - to a byte by adding the generic compression offset - and subtracting the window's offset*/ - else if(scsu_inDynamicWindow(comp, - curUC, comp->fCurrentWindow) ) { - *byteBuffer++ = (uint8_t) - (curUC - comp->fOffsets[ comp->fCurrentWindow ] - + COMPRESSIONOFFSET); - } + /* if the char belongs to current window, convert it + to a byte by adding the generic compression offset + and subtracting the window's offset*/ + else if(scsu_inDynamicWindow(comp, + curUC, comp->fCurrentWindow) ) { + *byteBuffer++ = (uint8_t) + (curUC - comp->fOffsets[ comp->fCurrentWindow ] + + COMPRESSIONOFFSET); + } - /* if char is not in compressible range, either switch - to or quote from unicode*/ - else if( ! scsu_isCompressible(curUC) ) { - /* only check next character if it is valid*/ - if(nextUC != INVALIDCHAR && scsu_isCompressible(nextUC)) { - /* make sure there is enough room to write all - three bytes if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if char is not in compressible range, either switch + to or quote from unicode*/ + else if( ! scsu_isCompressible(curUC) ) { + /* only check next character if it is valid*/ + if(nextUC != INVALIDCHAR && scsu_isCompressible(nextUC)) { + /* make sure there is enough room to write all + three bytes if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) SQUOTEU; - *byteBuffer++ = (uint8_t) (curUC >> 8); - *byteBuffer++ = (uint8_t) curUC; - } - else { - /* make sure there is enough room to write all - four bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 3) >= targetLimit) { - --unicharBuffer; - goto finish; - } + *byteBuffer++ = (uint8_t) SQUOTEU; + *byteBuffer++ = (uint8_t) (curUC >> 8); + *byteBuffer++ = (uint8_t) curUC; + } + else { + /* make sure there is enough room to write all + four bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 3) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) SCHANGEU; + *byteBuffer++ = (uint8_t) SCHANGEU; - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag */ - if( sUnicodeTagTable[hiByte] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag */ + if( sUnicodeTagTable[hiByte] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; - comp->fMode = UNICODEMODE; + comp->fMode = UNICODEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } + } - /* if the char is in a currently defined dynamic - window, figure out which one, and either switch to - it or quote from it*/ - else if( (whichWindow = scsu_findDynamicWindow(comp, curUC)) - != INVALIDWINDOW ) { - /* look ahead*/ - if( (unicharBuffer + 1) < sourceLimit ) - forwardUC = *(unicharBuffer + 1); - else - forwardUC = INVALIDCHAR; + /* if the char is in a currently defined dynamic + window, figure out which one, and either switch to + it or quote from it*/ + else if( (whichWindow = scsu_findDynamicWindow(comp, curUC)) + != INVALIDWINDOW ) { + /* look ahead*/ + if( (unicharBuffer + 1) < sourceLimit ) + forwardUC = *(unicharBuffer + 1); + else + forwardUC = INVALIDCHAR; - /* all three chars in same window, switch to that - window- inDynamicWindow will return FALSE for - INVALIDCHAR*/ - if( scsu_inDynamicWindow(comp, nextUC, whichWindow) - && scsu_inDynamicWindow(comp, forwardUC, whichWindow)){ - /* make sure there is enough room to write - both bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* all three chars in same window, switch to that + window- inDynamicWindow will return FALSE for + INVALIDCHAR*/ + if( scsu_inDynamicWindow(comp, nextUC, whichWindow) + && scsu_inDynamicWindow(comp, forwardUC, whichWindow)){ + /* make sure there is enough room to write + both bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) (SCHANGE0 + whichWindow); - *byteBuffer++ = (uint8_t) - (curUC - comp->fOffsets[whichWindow] - + COMPRESSIONOFFSET); - comp->fTimeStamps [ whichWindow ] = ++(comp->fTimeStamp); - comp->fCurrentWindow = whichWindow; - } + *byteBuffer++ = (uint8_t) (SCHANGE0 + whichWindow); + *byteBuffer++ = (uint8_t) + (curUC - comp->fOffsets[whichWindow] + + COMPRESSIONOFFSET); + comp->fTimeStamps [ whichWindow ] = ++(comp->fTimeStamp); + comp->fCurrentWindow = whichWindow; + } - /* either only next char or neither in same - window, so quote*/ - else { - /* make sure there is enough room to write - both bytes and if not, rewind the source stream - and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* either only next char or neither in same + window, so quote*/ + else { + /* make sure there is enough room to write + both bytes and if not, rewind the source stream + and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) (SQUOTE0 + whichWindow); - *byteBuffer++ = (uint8_t) - (curUC - comp->fOffsets[whichWindow] - + COMPRESSIONOFFSET); - } - } + *byteBuffer++ = (uint8_t) (SQUOTE0 + whichWindow); + *byteBuffer++ = (uint8_t) + (curUC - comp->fOffsets[whichWindow] + + COMPRESSIONOFFSET); + } + } - /* if a static window is defined, and the following - character is not in that static window, quote from - the static window Note: to quote from a static - window, don't add 0x80*/ - else if( (whichWindow = scsu_findStaticWindow(curUC)) - != INVALIDWINDOW - && ! scsu_inStaticWindow(nextUC, whichWindow) ) { - /* make sure there is enough room to write both - bytes if not, rewind the source stream and - break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if a static window is defined, and the following + character is not in that static window, quote from + the static window Note: to quote from a static + window, don't add 0x80*/ + else if( (whichWindow = scsu_findStaticWindow(curUC)) + != INVALIDWINDOW + && ! scsu_inStaticWindow(nextUC, whichWindow) ) { + /* make sure there is enough room to write both + bytes if not, rewind the source stream and + break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) (SQUOTE0 + whichWindow); - *byteBuffer++ = (uint8_t) (curUC - sOffsets[whichWindow]); - } + *byteBuffer++ = (uint8_t) (SQUOTE0 + whichWindow); + *byteBuffer++ = (uint8_t) (curUC - sOffsets[whichWindow]); + } - /* if a window is not defined, decide if we want to - define a new one or switch to unicode mode*/ - else { - /* determine index for current char (char is - compressible)*/ - curIndex = scsu_makeIndex(curUC); - comp->fIndexCount[curIndex]++; + /* if a window is not defined, decide if we want to + define a new one or switch to unicode mode*/ + else { + /* determine index for current char (char is + compressible)*/ + curIndex = scsu_makeIndex(curUC); + comp->fIndexCount[curIndex]++; - /* look ahead*/ - if( (unicharBuffer + 1) < sourceLimit ) - forwardUC = *(unicharBuffer + 1); - else - forwardUC = INVALIDCHAR; + /* look ahead*/ + if( (unicharBuffer + 1) < sourceLimit ) + forwardUC = *(unicharBuffer + 1); + else + forwardUC = INVALIDCHAR; - /* if we have encountered this index at least once - before, define a new window*/ - if( comp->fIndexCount[curIndex] > 1 ) { - /* make sure there is enough room to write all - three bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if we have encountered this index at least once + before, define a new window*/ + if( comp->fIndexCount[curIndex] > 1 ) { + /* make sure there is enough room to write all + three bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - /* get least recently defined window*/ - whichWindow = scsu_getLRDefinedWindow(comp); + /* get least recently defined window*/ + whichWindow = scsu_getLRDefinedWindow(comp); - *byteBuffer++ = (uint8_t) (SDEFINE0 + whichWindow); - *byteBuffer++ = (uint8_t) curIndex; - *byteBuffer++ = (uint8_t) - (curUC - sOffsetTable[curIndex] - + COMPRESSIONOFFSET); + *byteBuffer++ = (uint8_t) (SDEFINE0 + whichWindow); + *byteBuffer++ = (uint8_t) curIndex; + *byteBuffer++ = (uint8_t) + (curUC - sOffsetTable[curIndex] + + COMPRESSIONOFFSET); - comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; - comp->fCurrentWindow = whichWindow; - comp->fTimeStamps [whichWindow] = ++(comp->fTimeStamp); - } + comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; + comp->fCurrentWindow = whichWindow; + comp->fTimeStamps [whichWindow] = ++(comp->fTimeStamp); + } - /* three chars in a row with same index, define a - new window- makeIndex will return RESERVEDINDEX - for INVALIDCHAR*/ - else if( curIndex == scsu_makeIndex(nextUC) - && curIndex == scsu_makeIndex(forwardUC) ) { - /* make sure there is enough room to write all - three bytes if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* three chars in a row with same index, define a + new window- makeIndex will return RESERVEDINDEX + for INVALIDCHAR*/ + else if( curIndex == scsu_makeIndex(nextUC) + && curIndex == scsu_makeIndex(forwardUC) ) { + /* make sure there is enough room to write all + three bytes if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - whichWindow = scsu_getLRDefinedWindow(comp); + whichWindow = scsu_getLRDefinedWindow(comp); - *byteBuffer++ = (uint8_t) (SDEFINE0 + whichWindow); - *byteBuffer++ = (uint8_t) curIndex; - *byteBuffer++ = (uint8_t) - (curUC - sOffsetTable[curIndex] - + COMPRESSIONOFFSET); + *byteBuffer++ = (uint8_t) (SDEFINE0 + whichWindow); + *byteBuffer++ = (uint8_t) curIndex; + *byteBuffer++ = (uint8_t) + (curUC - sOffsetTable[curIndex] + + COMPRESSIONOFFSET); - comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; - comp->fCurrentWindow = whichWindow; - comp->fTimeStamps [whichWindow] = ++(comp->fTimeStamp); - } + comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; + comp->fCurrentWindow = whichWindow; + comp->fTimeStamps [whichWindow] = ++(comp->fTimeStamp); + } - /* only two chars in a row with same index, so - switch to unicode mode makeIndex will return - RESERVEDINDEX for INVALIDCHAR*/ - else if( curIndex == scsu_makeIndex(nextUC) - && curIndex != scsu_makeIndex(forwardUC) ) { - /* make sure there is enough room to write all - four bytes if not, rewind the source stream - and break out*/ - if( (byteBuffer + 3) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* only two chars in a row with same index, so + switch to unicode mode makeIndex will return + RESERVEDINDEX for INVALIDCHAR*/ + else if( curIndex == scsu_makeIndex(nextUC) + && curIndex != scsu_makeIndex(forwardUC) ) { + /* make sure there is enough room to write all + four bytes if not, rewind the source stream + and break out*/ + if( (byteBuffer + 3) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) SCHANGEU; + *byteBuffer++ = (uint8_t) SCHANGEU; - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag */ - if( sUnicodeTagTable[hiByte] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag */ + if( sUnicodeTagTable[hiByte] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; - comp->fMode = UNICODEMODE; + comp->fMode = UNICODEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } - /* three chars have different indices, so switch - to unicode mode*/ - else { - /* make sure there is enough room to write all - four bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 3) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* three chars have different indices, so switch + to unicode mode*/ + else { + /* make sure there is enough room to write all + four bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 3) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) SCHANGEU; + *byteBuffer++ = (uint8_t) SCHANGEU; - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag*/ - if( sUnicodeTagTable[ hiByte ] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag*/ + if( sUnicodeTagTable[ hiByte ] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; - comp->fMode = UNICODEMODE; + comp->fMode = UNICODEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } + } } break; @@ -581,245 +581,245 @@ scsu_compress(UnicodeCompressor *comp, case UNICODEMODE: while(unicharBuffer < sourceLimit && byteBuffer < targetLimit) { - /* get current char*/ - curUC = *unicharBuffer++; + /* get current char*/ + curUC = *unicharBuffer++; - /* get next char*/ - if( unicharBuffer < sourceLimit ) - nextUC = *unicharBuffer; - else - nextUC = INVALIDCHAR; + /* get next char*/ + if( unicharBuffer < sourceLimit ) + nextUC = *unicharBuffer; + else + nextUC = INVALIDCHAR; - /* if we have two uncompressible unichars in a row, - put the current char's bytes in the stream*/ - if( ! scsu_isCompressible(curUC) - || (nextUC != INVALIDCHAR - && ! scsu_isCompressible(nextUC)) ) { - /* make sure there is enough room to write all - three bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if we have two uncompressible unichars in a row, + put the current char's bytes in the stream*/ + if( ! scsu_isCompressible(curUC) + || (nextUC != INVALIDCHAR + && ! scsu_isCompressible(nextUC)) ) { + /* make sure there is enough room to write all + three bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag*/ - if( sUnicodeTagTable[ hiByte ] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag*/ + if( sUnicodeTagTable[ hiByte ] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; - } + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; + } - /* bytes less than 0x80 can go straight in the stream, - but in single-byte mode*/ - else if( curUC < 0x0080 ) { - loByte = curUC; + /* bytes less than 0x80 can go straight in the stream, + but in single-byte mode*/ + else if( curUC < 0x0080 ) { + loByte = curUC; - /* if two chars in a row below 0x80 and the - current char is not a single-byte mode tag, - switch to single-byte mode*/ - if(nextUC != INVALIDCHAR - && nextUC < 0x0080 && ! sSingleTagTable[ loByte ] ) { - /* make sure there is enough room to write - both bytes and if not, rewind the source stream - and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if two chars in a row below 0x80 and the + current char is not a single-byte mode tag, + switch to single-byte mode*/ + if(nextUC != INVALIDCHAR + && nextUC < 0x0080 && ! sSingleTagTable[ loByte ] ) { + /* make sure there is enough room to write + both bytes and if not, rewind the source stream + and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - /* use window 0, but any would work*/ - *byteBuffer++ = (uint8_t) UCHANGE0; - *byteBuffer++ = (uint8_t) loByte; + /* use window 0, but any would work*/ + *byteBuffer++ = (uint8_t) UCHANGE0; + *byteBuffer++ = (uint8_t) loByte; - comp->fCurrentWindow = 0; - comp->fTimeStamps [0] = ++(comp->fTimeStamp); - comp->fMode = SINGLEBYTEMODE; + comp->fCurrentWindow = 0; + comp->fTimeStamps [0] = ++(comp->fTimeStamp); + comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } - /* otherwise, just write the bytes to the stream - (this will cover the case of only 1 char less - than 0x80 and single-byte mode tags)*/ - else { - /* make sure there is enough room to write - both bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* otherwise, just write the bytes to the stream + (this will cover the case of only 1 char less + than 0x80 and single-byte mode tags)*/ + else { + /* make sure there is enough room to write + both bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - /* since the character is less than 0x80, the - high byte is always 0x00 - no need for - (curUC >> 8)*/ - *byteBuffer++ = (uint8_t) 0x00; - *byteBuffer++ = (uint8_t) loByte; - } - } + /* since the character is less than 0x80, the + high byte is always 0x00 - no need for + (curUC >> 8)*/ + *byteBuffer++ = (uint8_t) 0x00; + *byteBuffer++ = (uint8_t) loByte; + } + } - /* figure out if the current unichar is in a defined - window*/ - else if( (whichWindow = scsu_findDynamicWindow(comp, curUC)) - != INVALIDWINDOW ) { - /* if two chars in a row in the same window, - switch to that window and go to single-byte - mode inDynamicWindow will return FALSE for - INVALIDCHAR*/ - if( scsu_inDynamicWindow(comp, nextUC, whichWindow) ) { - /* make sure there is enough room to write - both bytes if not, rewind the source stream - and break out*/ - if( (byteBuffer + 1) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* figure out if the current unichar is in a defined + window*/ + else if( (whichWindow = scsu_findDynamicWindow(comp, curUC)) + != INVALIDWINDOW ) { + /* if two chars in a row in the same window, + switch to that window and go to single-byte + mode inDynamicWindow will return FALSE for + INVALIDCHAR*/ + if( scsu_inDynamicWindow(comp, nextUC, whichWindow) ) { + /* make sure there is enough room to write + both bytes if not, rewind the source stream + and break out*/ + if( (byteBuffer + 1) >= targetLimit) { + --unicharBuffer; + goto finish; + } - *byteBuffer++ = (uint8_t) (UCHANGE0 + whichWindow); - *byteBuffer++ = (uint8_t) - (curUC - comp->fOffsets[whichWindow] - + COMPRESSIONOFFSET); + *byteBuffer++ = (uint8_t) (UCHANGE0 + whichWindow); + *byteBuffer++ = (uint8_t) + (curUC - comp->fOffsets[whichWindow] + + COMPRESSIONOFFSET); - comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); - comp->fCurrentWindow = whichWindow; - comp->fMode = SINGLEBYTEMODE; + comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); + comp->fCurrentWindow = whichWindow; + comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } - /* otherwise, just quote the unicode for the - char*/ - else { - /* make sure there is enough room to write all - three bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* otherwise, just quote the unicode for the + char*/ + else { + /* make sure there is enough room to write all + three bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag*/ - if( sUnicodeTagTable[ hiByte ] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag*/ + if( sUnicodeTagTable[ hiByte ] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; - } - } + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; + } + } - /* char is not in a defined window*/ - else { - /* determine index for current char (char is - compressible)*/ - curIndex = scsu_makeIndex(curUC); - comp->fIndexCount[curIndex]++; + /* char is not in a defined window*/ + else { + /* determine index for current char (char is + compressible)*/ + curIndex = scsu_makeIndex(curUC); + comp->fIndexCount[curIndex]++; - /* look ahead*/ - if( (unicharBuffer + 1) < sourceLimit ) - forwardUC = *unicharBuffer; - else - forwardUC = INVALIDCHAR; + /* look ahead*/ + if( (unicharBuffer + 1) < sourceLimit ) + forwardUC = *unicharBuffer; + else + forwardUC = INVALIDCHAR; - /* if we have encountered this index at least once - before, define a new window for it that hasn't - previously been redefined*/ - if( comp->fIndexCount[curIndex] > 1 ) { - /* make sure there is enough room to write all - three bytes if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if we have encountered this index at least once + before, define a new window for it that hasn't + previously been redefined*/ + if( comp->fIndexCount[curIndex] > 1 ) { + /* make sure there is enough room to write all + three bytes if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - /* get least recently defined window*/ - whichWindow = scsu_getLRDefinedWindow(comp); + /* get least recently defined window*/ + whichWindow = scsu_getLRDefinedWindow(comp); - *byteBuffer++ = (uint8_t) (UDEFINE0 + whichWindow); - *byteBuffer++ = (uint8_t) curIndex; - *byteBuffer++ = (uint8_t) - (curUC - sOffsetTable[curIndex] - + COMPRESSIONOFFSET); + *byteBuffer++ = (uint8_t) (UDEFINE0 + whichWindow); + *byteBuffer++ = (uint8_t) curIndex; + *byteBuffer++ = (uint8_t) + (curUC - sOffsetTable[curIndex] + + COMPRESSIONOFFSET); - comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; - comp->fCurrentWindow = whichWindow; - comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); - comp->fMode = SINGLEBYTEMODE; + comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; + comp->fCurrentWindow = whichWindow; + comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); + comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } - /* if three chars in a row with the same index, - define a new window makeIndex will return - RESERVEDINDEX for INVALIDCHAR*/ - else if( curIndex == scsu_makeIndex(nextUC) - && curIndex == scsu_makeIndex(forwardUC) ) { - /* make sure there is enough room to write all - three bytes if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* if three chars in a row with the same index, + define a new window makeIndex will return + RESERVEDINDEX for INVALIDCHAR*/ + else if( curIndex == scsu_makeIndex(nextUC) + && curIndex == scsu_makeIndex(forwardUC) ) { + /* make sure there is enough room to write all + three bytes if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - whichWindow = scsu_getLRDefinedWindow(comp); + whichWindow = scsu_getLRDefinedWindow(comp); - *byteBuffer++ = (uint8_t) (UDEFINE0 + whichWindow); - *byteBuffer++ = (uint8_t) curIndex; - *byteBuffer++ = (uint8_t) - (curUC - sOffsetTable[curIndex] - + COMPRESSIONOFFSET); + *byteBuffer++ = (uint8_t) (UDEFINE0 + whichWindow); + *byteBuffer++ = (uint8_t) curIndex; + *byteBuffer++ = (uint8_t) + (curUC - sOffsetTable[curIndex] + + COMPRESSIONOFFSET); - comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; - comp->fCurrentWindow = whichWindow; - comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); - comp->fMode = SINGLEBYTEMODE; + comp->fOffsets[whichWindow] = sOffsetTable[curIndex]; + comp->fCurrentWindow = whichWindow; + comp->fTimeStamps[whichWindow] = ++(comp->fTimeStamp); + comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having - to check fMode in the while loop at the top - of the case */ - goto mainLoop; - } + /* use a goto here for speed, to avoid having + to check fMode in the while loop at the top + of the case */ + goto mainLoop; + } - /* otherwise just quote the unicode, and save our - windows for longer runs*/ - else { - /* make sure there is enough room to write all - three bytes and if not, rewind the source - stream and break out*/ - if( (byteBuffer + 2) >= targetLimit) { - --unicharBuffer; - goto finish; - } + /* otherwise just quote the unicode, and save our + windows for longer runs*/ + else { + /* make sure there is enough room to write all + three bytes and if not, rewind the source + stream and break out*/ + if( (byteBuffer + 2) >= targetLimit) { + --unicharBuffer; + goto finish; + } - hiByte = curUC >> 8; - loByte = curUC; + hiByte = curUC >> 8; + loByte = curUC; - /* add quote Unicode tag*/ - if( sUnicodeTagTable[ hiByte ] ) - *byteBuffer++ = (uint8_t) UQUOTEU; + /* add quote Unicode tag*/ + if( sUnicodeTagTable[ hiByte ] ) + *byteBuffer++ = (uint8_t) UQUOTEU; - *byteBuffer++ = (uint8_t) hiByte; - *byteBuffer++ = (uint8_t) loByte; - } - } + *byteBuffer++ = (uint8_t) hiByte; + *byteBuffer++ = (uint8_t) loByte; + } + } } } /* end switch*/ } @@ -909,205 +909,205 @@ scsu_decompress(UnicodeCompressor *comp, case SINGLEBYTEMODE: while(byteBuffer < sourceLimit && unicharBuffer < targetLimit) { - /* get the next byte */ - aByte = *byteBuffer++; + /* get the next byte */ + aByte = *byteBuffer++; - switch(aByte) { - /* All bytes from 0x80 through 0xFF are remapped to - chars or surrogate pairs according to the currently - active window */ - case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: - case 0x85: case 0x86: case 0x87: case 0x88: case 0x89: - case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: - case 0x8F: case 0x90: case 0x91: case 0x92: case 0x93: - case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: - case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: - case 0x9E: case 0x9F: case 0xA0: case 0xA1: case 0xA2: - case 0xA3: case 0xA4: case 0xA5: case 0xA6: case 0xA7: - case 0xA8: case 0xA9: case 0xAA: case 0xAB: case 0xAC: - case 0xAD: case 0xAE: case 0xAF: case 0xB0: case 0xB1: - case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: - case 0xB7: case 0xB8: case 0xB9: case 0xBA: case 0xBB: - case 0xBC: case 0xBD: case 0xBE: case 0xBF: case 0xC0: - case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: - case 0xC6: case 0xC7: case 0xC8: case 0xC9: case 0xCA: - case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: - case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: - case 0xD5: case 0xD6: case 0xD7: case 0xD8: case 0xD9: - case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: - case 0xDF: case 0xE0: case 0xE1: case 0xE2: case 0xE3: - case 0xE4: case 0xE5: case 0xE6: case 0xE7: case 0xE8: - case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: - case 0xEE: case 0xEF: case 0xF0: case 0xF1: case 0xF2: - case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7: - case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: - case 0xFD: case 0xFE: case 0xFF: + switch(aByte) { + /* All bytes from 0x80 through 0xFF are remapped to + chars or surrogate pairs according to the currently + active window */ + case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: + case 0x85: case 0x86: case 0x87: case 0x88: case 0x89: + case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: + case 0x8F: case 0x90: case 0x91: case 0x92: case 0x93: + case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: + case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: + case 0x9E: case 0x9F: case 0xA0: case 0xA1: case 0xA2: + case 0xA3: case 0xA4: case 0xA5: case 0xA6: case 0xA7: + case 0xA8: case 0xA9: case 0xAA: case 0xAB: case 0xAC: + case 0xAD: case 0xAE: case 0xAF: case 0xB0: case 0xB1: + case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: + case 0xB7: case 0xB8: case 0xB9: case 0xBA: case 0xBB: + case 0xBC: case 0xBD: case 0xBE: case 0xBF: case 0xC0: + case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: + case 0xC6: case 0xC7: case 0xC8: case 0xC9: case 0xCA: + case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: + case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: + case 0xD5: case 0xD6: case 0xD7: case 0xD8: case 0xD9: + case 0xDA: case 0xDB: case 0xDC: case 0xDD: case 0xDE: + case 0xDF: case 0xE0: case 0xE1: case 0xE2: case 0xE3: + case 0xE4: case 0xE5: case 0xE6: case 0xE7: case 0xE8: + case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: + case 0xEE: case 0xEF: case 0xF0: case 0xF1: case 0xF2: + case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7: + case 0xF8: case 0xF9: case 0xFA: case 0xFB: case 0xFC: + case 0xFD: case 0xFE: case 0xFF: - /* For offsets <= 0xFFFF, convert to a single char by - adding the window's offset and subtracting the - generic compression offset*/ - if(comp->fOffsets[ comp->fCurrentWindow ] <= 0xFFFF) { - *unicharBuffer++ = (UChar) - (aByte + comp->fOffsets[comp->fCurrentWindow] - - COMPRESSIONOFFSET); - } - /* For offsets > 0x10000, convert to a surrogate pair by - normBase = window's offset - 0x10000 - high surrogate = 0xD800 + (normBase >> 10) - low surrogate = 0xDC00 + (normBase & 0x3FF) - + (byte & 0x7F) */ - else { - /* make sure there is enough room to write - both characters - if not, save state and break out */ - if((unicharBuffer + 1) >= targetLimit) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* For offsets <= 0xFFFF, convert to a single char by + adding the window's offset and subtracting the + generic compression offset*/ + if(comp->fOffsets[ comp->fCurrentWindow ] <= 0xFFFF) { + *unicharBuffer++ = (UChar) + (aByte + comp->fOffsets[comp->fCurrentWindow] + - COMPRESSIONOFFSET); + } + /* For offsets > 0x10000, convert to a surrogate pair by + normBase = window's offset - 0x10000 + high surrogate = 0xD800 + (normBase >> 10) + low surrogate = 0xDC00 + (normBase & 0x3FF) + + (byte & 0x7F) */ + else { + /* make sure there is enough room to write + both characters + if not, save state and break out */ + if((unicharBuffer + 1) >= targetLimit) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - normalizedBase = comp->fOffsets[comp->fCurrentWindow] - - 0x10000; - *unicharBuffer++ = - (UChar) (0xD800 + (normalizedBase >> 10)); - *unicharBuffer++ = (UChar) - (0xDC00 + (normalizedBase & 0x3FF) - + (aByte & 0x7F)); - } - break; + normalizedBase = comp->fOffsets[comp->fCurrentWindow] + - 0x10000; + *unicharBuffer++ = + (UChar) (0xD800 + (normalizedBase >> 10)); + *unicharBuffer++ = (UChar) + (0xDC00 + (normalizedBase & 0x3FF) + + (aByte & 0x7F)); + } + break; - /* bytes from 0x20 through 0x7F are treated as ASCII - and are remapped to chars by padding the high byte - (this is the same as quoting from static window 0) - NUL (0x00), HT (0x09), CR (0x0A), LF (0x0D) are - treated as ASCII as well*/ - case 0x00: case 0x09: case 0x0A: case 0x0D: - case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: - case 0x25: case 0x26: case 0x27: case 0x28: case 0x29: - case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: - case 0x2F: case 0x30: case 0x31: case 0x32: case 0x33: - case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: - case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: - case 0x3E: case 0x3F: case 0x40: case 0x41: case 0x42: - case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: - case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: - case 0x4D: case 0x4E: case 0x4F: case 0x50: case 0x51: - case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: - case 0x57: case 0x58: case 0x59: case 0x5A: case 0x5B: - case 0x5C: case 0x5D: case 0x5E: case 0x5F: case 0x60: - case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: - case 0x66: case 0x67: case 0x68: case 0x69: case 0x6A: - case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F: - case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: - case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: - case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: - case 0x7F: - *unicharBuffer++ = (UChar) aByte; - break; + /* bytes from 0x20 through 0x7F are treated as ASCII + and are remapped to chars by padding the high byte + (this is the same as quoting from static window 0) + NUL (0x00), HT (0x09), CR (0x0A), LF (0x0D) are + treated as ASCII as well*/ + case 0x00: case 0x09: case 0x0A: case 0x0D: + case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: + case 0x25: case 0x26: case 0x27: case 0x28: case 0x29: + case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2E: + case 0x2F: case 0x30: case 0x31: case 0x32: case 0x33: + case 0x34: case 0x35: case 0x36: case 0x37: case 0x38: + case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: + case 0x3E: case 0x3F: case 0x40: case 0x41: case 0x42: + case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: + case 0x48: case 0x49: case 0x4A: case 0x4B: case 0x4C: + case 0x4D: case 0x4E: case 0x4F: case 0x50: case 0x51: + case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: + case 0x57: case 0x58: case 0x59: case 0x5A: case 0x5B: + case 0x5C: case 0x5D: case 0x5E: case 0x5F: case 0x60: + case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: + case 0x66: case 0x67: case 0x68: case 0x69: case 0x6A: + case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F: + case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: + case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: + case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: + case 0x7F: + *unicharBuffer++ = (UChar) aByte; + break; - /* quote unicode*/ - case SQUOTEU: - /* verify we have two bytes following tag and if not, - rewind the source stream and break out */ - if( (byteBuffer + 1) >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* quote unicode*/ + case SQUOTEU: + /* verify we have two bytes following tag and if not, + rewind the source stream and break out */ + if( (byteBuffer + 1) >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - aByte = *byteBuffer++; - *unicharBuffer++ = - (UChar) (aByte << 8 | *byteBuffer++); - break; + aByte = *byteBuffer++; + *unicharBuffer++ = + (UChar) (aByte << 8 | *byteBuffer++); + break; - /* switch to Unicode mode*/ - case SCHANGEU: - comp->fMode = UNICODEMODE; - /* use a goto here for speed, to avoid having to check - fMode in the while loop at the top of the case */ - goto mainLoop; - break; + /* switch to Unicode mode*/ + case SCHANGEU: + comp->fMode = UNICODEMODE; + /* use a goto here for speed, to avoid having to check + fMode in the while loop at the top of the case */ + goto mainLoop; + break; - /* handle all quote tags*/ - case SQUOTE0: case SQUOTE1: case SQUOTE2: case SQUOTE3: - case SQUOTE4: case SQUOTE5: case SQUOTE6: case SQUOTE7: - /* verify there is a byte following the tag and if - not, rewind the source stream and break out*/ - if( byteBuffer >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* handle all quote tags*/ + case SQUOTE0: case SQUOTE1: case SQUOTE2: case SQUOTE3: + case SQUOTE4: case SQUOTE5: case SQUOTE6: case SQUOTE7: + /* verify there is a byte following the tag and if + not, rewind the source stream and break out*/ + if( byteBuffer >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - /* if the byte is in the range 0x00 - 0x7F, use static - window n- otherwise, use dynamic window n */ - dByte = *byteBuffer++; - *unicharBuffer++ = (UChar) - (dByte + (dByte >= 0x00 && dByte < 0x80 - ? sOffsets[aByte - SQUOTE0] - : (comp->fOffsets[aByte - SQUOTE0] - - COMPRESSIONOFFSET))); - break; + /* if the byte is in the range 0x00 - 0x7F, use static + window n- otherwise, use dynamic window n */ + dByte = *byteBuffer++; + *unicharBuffer++ = (UChar) + (dByte + (dByte >= 0x00 && dByte < 0x80 + ? sOffsets[aByte - SQUOTE0] + : (comp->fOffsets[aByte - SQUOTE0] + - COMPRESSIONOFFSET))); + break; - /* handle all change tags*/ - case SCHANGE0: case SCHANGE1: case SCHANGE2: case SCHANGE3: - case SCHANGE4: case SCHANGE5: case SCHANGE6: case SCHANGE7: - comp->fCurrentWindow = (aByte - SCHANGE0); - break; + /* handle all change tags*/ + case SCHANGE0: case SCHANGE1: case SCHANGE2: case SCHANGE3: + case SCHANGE4: case SCHANGE5: case SCHANGE6: case SCHANGE7: + comp->fCurrentWindow = (aByte - SCHANGE0); + break; - /* handle all define tags*/ - case SDEFINE0: case SDEFINE1: case SDEFINE2: case SDEFINE3: - case SDEFINE4: case SDEFINE5: case SDEFINE6: case SDEFINE7: - /* verify there is a byte following the tag and if - not, rewind the source stream and break out*/ - if( byteBuffer >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* handle all define tags*/ + case SDEFINE0: case SDEFINE1: case SDEFINE2: case SDEFINE3: + case SDEFINE4: case SDEFINE5: case SDEFINE6: case SDEFINE7: + /* verify there is a byte following the tag and if + not, rewind the source stream and break out*/ + if( byteBuffer >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - comp->fCurrentWindow = (aByte - SDEFINE0); - comp->fOffsets[comp->fCurrentWindow] = - sOffsetTable[*byteBuffer++]; - break; + comp->fCurrentWindow = (aByte - SDEFINE0); + comp->fOffsets[comp->fCurrentWindow] = + sOffsetTable[*byteBuffer++]; + break; - /* handle define extended tag*/ - case SDEFINEX: - /* verify we have two bytes following tag and if not, - rewind the source stream and break out*/ - if( (byteBuffer + 1) >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* handle define extended tag*/ + case SDEFINEX: + /* verify we have two bytes following tag and if not, + rewind the source stream and break out*/ + if( (byteBuffer + 1) >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - aByte = *byteBuffer++; - comp->fCurrentWindow = (aByte & 0xE0) >> 5; - comp->fOffsets[comp->fCurrentWindow] = 0x10000 - + (0x80 - * (((aByte & 0x1F) << 8) | *byteBuffer++)); - break; + aByte = *byteBuffer++; + comp->fCurrentWindow = (aByte & 0xE0) >> 5; + comp->fOffsets[comp->fCurrentWindow] = 0x10000 + + (0x80 + * (((aByte & 0x1F) << 8) | *byteBuffer++)); + break; - /* reserved, shouldn't happen*/ - case SRESERVED: - break; + /* reserved, shouldn't happen*/ + case SRESERVED: + break; - } /* end switch*/ + } /* end switch*/ } /* end while*/ break; @@ -1115,108 +1115,108 @@ scsu_decompress(UnicodeCompressor *comp, case UNICODEMODE: while( byteBuffer < sourceLimit && unicharBuffer < targetLimit ) { - /* get the next byte */ - aByte = *byteBuffer++; + /* get the next byte */ + aByte = *byteBuffer++; - switch( aByte ) { - /* handle all define tags*/ - case UDEFINE0: case UDEFINE1: case UDEFINE2: case UDEFINE3: - case UDEFINE4: case UDEFINE5: case UDEFINE6: case UDEFINE7: - /* verify there is a byte following tag and if not, - rewind the source stream and break out*/ - if( byteBuffer >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + switch( aByte ) { + /* handle all define tags*/ + case UDEFINE0: case UDEFINE1: case UDEFINE2: case UDEFINE3: + case UDEFINE4: case UDEFINE5: case UDEFINE6: case UDEFINE7: + /* verify there is a byte following tag and if not, + rewind the source stream and break out*/ + if( byteBuffer >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - comp->fCurrentWindow = (aByte - UDEFINE0); - comp->fOffsets[comp->fCurrentWindow] = - sOffsetTable[*byteBuffer++]; - comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having to check - fMode in the while loop at the top of the case */ - goto mainLoop; - break; + comp->fCurrentWindow = (aByte - UDEFINE0); + comp->fOffsets[comp->fCurrentWindow] = + sOffsetTable[*byteBuffer++]; + comp->fMode = SINGLEBYTEMODE; + /* use a goto here for speed, to avoid having to check + fMode in the while loop at the top of the case */ + goto mainLoop; + break; - /* handle define extended tag*/ - case UDEFINEX: - /* verify we have two bytes following tag if not, - rewind the source stream and break out*/ - if( (byteBuffer + 1) >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* handle define extended tag*/ + case UDEFINEX: + /* verify we have two bytes following tag if not, + rewind the source stream and break out*/ + if( (byteBuffer + 1) >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - aByte = *byteBuffer++; - comp->fCurrentWindow = (aByte & 0xE0) >> 5; - comp->fOffsets[comp->fCurrentWindow] = 0x10000 - + (0x80 - * (((aByte & 0x1F) << 8) | *byteBuffer++)); - comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having to check - fMode in the while loop at the top of the case */ - goto mainLoop; - break; + aByte = *byteBuffer++; + comp->fCurrentWindow = (aByte & 0xE0) >> 5; + comp->fOffsets[comp->fCurrentWindow] = 0x10000 + + (0x80 + * (((aByte & 0x1F) << 8) | *byteBuffer++)); + comp->fMode = SINGLEBYTEMODE; + /* use a goto here for speed, to avoid having to check + fMode in the while loop at the top of the case */ + goto mainLoop; + break; - /* handle all change tags*/ - case UCHANGE0: case UCHANGE1: case UCHANGE2: case UCHANGE3: - case UCHANGE4: case UCHANGE5: case UCHANGE6: case UCHANGE7: - comp->fCurrentWindow = (aByte - UCHANGE0); - comp->fMode = SINGLEBYTEMODE; - /* use a goto here for speed, to avoid having to check - fMode in the while loop at the top of the case */ - goto mainLoop; - break; + /* handle all change tags*/ + case UCHANGE0: case UCHANGE1: case UCHANGE2: case UCHANGE3: + case UCHANGE4: case UCHANGE5: case UCHANGE6: case UCHANGE7: + comp->fCurrentWindow = (aByte - UCHANGE0); + comp->fMode = SINGLEBYTEMODE; + /* use a goto here for speed, to avoid having to check + fMode in the while loop at the top of the case */ + goto mainLoop; + break; - /* quote unicode*/ - case UQUOTEU: - /* verify we have two bytes following tag if not, - rewind the source stream and break out*/ - if( byteBuffer >= sourceLimit - 1) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + /* quote unicode*/ + case UQUOTEU: + /* verify we have two bytes following tag if not, + rewind the source stream and break out*/ + if( byteBuffer >= sourceLimit - 1) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - aByte = *byteBuffer++; - *unicharBuffer++ = (UChar) - (aByte << 8 | *byteBuffer++); - break; + aByte = *byteBuffer++; + *unicharBuffer++ = (UChar) + (aByte << 8 | *byteBuffer++); + break; - default: - /* verify there is a byte following tag if not, rewind - the source stream and break out*/ - if( byteBuffer >= sourceLimit ) { - --byteBuffer; - uprv_memcpy(comp->fBuffer, byteBuffer, - sourceLimit - byteBuffer); - comp->fBufferLength = sourceLimit - byteBuffer; - byteBuffer += comp->fBufferLength; - goto finish; - } + default: + /* verify there is a byte following tag if not, rewind + the source stream and break out*/ + if( byteBuffer >= sourceLimit ) { + --byteBuffer; + uprv_memcpy(comp->fBuffer, byteBuffer, + sourceLimit - byteBuffer); + comp->fBufferLength = sourceLimit - byteBuffer; + byteBuffer += comp->fBufferLength; + goto finish; + } - *unicharBuffer++ = (UChar) (aByte << 8 | *byteBuffer++); - break; + *unicharBuffer++ = (UChar) (aByte << 8 | *byteBuffer++); + break; - } /* end switch*/ + } /* end switch*/ } /* end while*/ break; } /* end switch( comp->fMode )*/ } /* end while*/ - + finish: /* fill in return values*/ diff --git a/icu4c/source/common/ubidi.c b/icu4c/source/common/ubidi.c index cb1dd34fa8..22ba0a0fc8 100644 --- a/icu4c/source/common/ubidi.c +++ b/icu4c/source/common/ubidi.c @@ -130,9 +130,9 @@ static void adjustWSLevels(UBiDi *pBiDi); /* to avoid some conditional statements, use tiny constant arrays */ -static Flags flagLR[2]={ DIRPROP_FLAG(L), DIRPROP_FLAG(R) }; -static Flags flagE[2]={ DIRPROP_FLAG(LRE), DIRPROP_FLAG(RLE) }; -static Flags flagO[2]={ DIRPROP_FLAG(LRO), DIRPROP_FLAG(RLO) }; +static const Flags flagLR[2]={ DIRPROP_FLAG(L), DIRPROP_FLAG(R) }; +static const Flags flagE[2]={ DIRPROP_FLAG(LRE), DIRPROP_FLAG(RLE) }; +static const Flags flagO[2]={ DIRPROP_FLAG(LRO), DIRPROP_FLAG(RLO) }; #define DIRPROP_FLAG_LR(level) flagLR[(level)&1] #define DIRPROP_FLAG_E(level) flagE[(level)&1] diff --git a/icu4c/source/common/uhash.c b/icu4c/source/common/uhash.c index 64a10c2177..a2bc897de8 100644 --- a/icu4c/source/common/uhash.c +++ b/icu4c/source/common/uhash.c @@ -71,7 +71,7 @@ * ratio is changed, the low and high water ratios should also be * adjusted to suit. */ -static int32_t PRIMES[] = { +static const int32_t PRIMES[] = { 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459, 536870923, diff --git a/icu4c/source/common/umemstrm.c b/icu4c/source/common/umemstrm.c index 1ba062c790..90c927a260 100644 --- a/icu4c/source/common/umemstrm.c +++ b/icu4c/source/common/umemstrm.c @@ -204,7 +204,7 @@ uprv_mstrm_writeBlock(UMemoryStream *MS, const void *s, UTextOffset length) { U_CAPI void U_EXPORT2 uprv_mstrm_writePadding(UMemoryStream *MS, UTextOffset length) { - static uint8_t padding[16]={ + static const uint8_t padding[16]={ 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,