ICU-406 putting collation data in resource bundles (initial revision)
X-SVN-Rev: 1427
This commit is contained in:
parent
e35f1c9533
commit
ca5cb935ca
@ -69,7 +69,7 @@ LIBS = @LIBS@
|
||||
|
||||
|
||||
OBJECTS = chariter.o umutex.o compdata.o compitr.o convert.o \
|
||||
cpputils.o cstring.o dcmpdata.o digitlst.o filestrm.o locid.o locmap.o \
|
||||
cpputils.o cstring.o dcmpdata.o digitlst.o filestrm.o umemstrm.o locid.o locmap.o \
|
||||
mutex.o normlzr.o putil.o rbcache.o resbund.o schriter.o scsu.o \
|
||||
uchar.o uchriter.o ucmp8.o ucmp16.o ucmp32.o ucnv.o ucnv_bld.o \
|
||||
ucnv_cnv.o ucnv_err.o ucnv_io.o uhash.o uhash_us.o uloc.o unicode.o unistr.o \
|
||||
|
@ -118,6 +118,87 @@ if (!T_FileStream_error(os))
|
||||
}
|
||||
}
|
||||
|
||||
U_CAPI void ucmp32_streamMemIn(CompactIntArray* this_obj, UMemoryStream* is)
|
||||
{
|
||||
int32_t newCount, len;
|
||||
char c;
|
||||
if (!uprv_mstrm_error(is))
|
||||
{
|
||||
|
||||
uprv_mstrm_read(is, &newCount, sizeof(newCount));
|
||||
if (this_obj->fCount != newCount)
|
||||
{
|
||||
this_obj->fCount = newCount;
|
||||
uprv_free(this_obj->fArray);
|
||||
this_obj->fArray = 0;
|
||||
this_obj->fArray = (int32_t*)uprv_malloc(this_obj->fCount * sizeof(int32_t));
|
||||
if (!this_obj->fArray) {
|
||||
this_obj->fBogus = TRUE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
uprv_mstrm_read(is, this_obj->fArray, sizeof(*(this_obj->fArray)) * this_obj->fCount);
|
||||
uprv_mstrm_read(is, &len, sizeof(len));
|
||||
if (len == 0)
|
||||
{
|
||||
uprv_free(this_obj->fIndex);
|
||||
this_obj->fIndex = 0;
|
||||
}
|
||||
else if (len == UCMP32_kIndexCount)
|
||||
{
|
||||
if (this_obj->fIndex == 0)
|
||||
this_obj->fIndex =(uint16_t*)uprv_malloc(UCMP32_kIndexCount * sizeof(uint16_t));
|
||||
if (!this_obj->fIndex) {
|
||||
this_obj->fBogus = TRUE;
|
||||
uprv_free(this_obj->fArray);
|
||||
this_obj->fArray = 0;
|
||||
return;
|
||||
}
|
||||
uprv_mstrm_read(is, this_obj->fIndex, sizeof(*(this_obj->fIndex)) * UCMP32_kIndexCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
this_obj->fBogus = TRUE;
|
||||
return;
|
||||
}
|
||||
/* char instead of int8_t for Mac compilation*/
|
||||
uprv_mstrm_read(is, (char*)&c, sizeof(c));
|
||||
this_obj->fCompact = (c != 0);
|
||||
}
|
||||
}
|
||||
|
||||
U_CAPI void ucmp32_streamMemOut(CompactIntArray* this_obj, UMemoryStream* os)
|
||||
{
|
||||
char c;
|
||||
if (!uprv_mstrm_error(os))
|
||||
{
|
||||
if (this_obj->fCount != 0 && this_obj->fArray != 0)
|
||||
{
|
||||
uprv_mstrm_write(os, (uint8_t *)&(this_obj->fCount), sizeof(this_obj->fCount));
|
||||
uprv_mstrm_write(os, (uint8_t *)this_obj->fArray, sizeof(*(this_obj->fArray)) * this_obj->fCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t zero = 0;
|
||||
uprv_mstrm_write(os, (uint8_t *)&zero, sizeof(zero));
|
||||
}
|
||||
|
||||
if (this_obj->fIndex == 0)
|
||||
{
|
||||
int32_t len = 0;
|
||||
uprv_mstrm_write(os, (uint8_t *)&len, sizeof(len));
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t len = UCMP32_kIndexCount;
|
||||
uprv_mstrm_write(os, (uint8_t *)&len, sizeof(len));
|
||||
uprv_mstrm_write(os, (uint8_t *)this_obj->fIndex, sizeof(*(this_obj->fIndex)) * UCMP32_kIndexCount);
|
||||
}
|
||||
c = this_obj->fCompact ? 1 : 0; /* char instead of int8_t for Mac compilation*/
|
||||
uprv_mstrm_write(os, (const char*)&c, sizeof(c));
|
||||
}
|
||||
}
|
||||
|
||||
CompactIntArray* ucmp32_open(int32_t defaultValue)
|
||||
{
|
||||
uint16_t i;
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
#include "filestrm.h"
|
||||
#include "umemstrm.h"
|
||||
|
||||
/* INTERNAL CONSTANTS */
|
||||
#define UCMP32_kBlockShift 7
|
||||
@ -75,7 +76,7 @@
|
||||
* @see CompactIntArray
|
||||
* @see CompactCharArray
|
||||
* @see CompactStringArray
|
||||
* @version $Revision: 1.9 $ 8/25/98
|
||||
* @version $Revision: 1.10 $ 8/25/98
|
||||
* @author Helena Shih
|
||||
*/
|
||||
/*====================================*/
|
||||
@ -198,6 +199,9 @@ U_CAPI const uint16_t* U_EXPORT2 ucmp32_getIndex(const CompactIntArray* array);
|
||||
U_CAPI void U_EXPORT2 ucmp32_streamIn( CompactIntArray* array, FileStream* is);
|
||||
U_CAPI void U_EXPORT2 ucmp32_streamOut(CompactIntArray* array, FileStream* os);
|
||||
|
||||
U_CAPI void U_EXPORT2 ucmp32_streamMemIn( CompactIntArray* array, UMemoryStream* is);
|
||||
U_CAPI void U_EXPORT2 ucmp32_streamMemOut(CompactIntArray* array, UMemoryStream* os);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -36,6 +36,7 @@ U_CAPI UMemoryStream * U_EXPORT2 uprv_mstrm_openNew(int32_t size) {
|
||||
MS->fPos = 0;
|
||||
MS->fReadPos = 0;
|
||||
MS->fError = FALSE;
|
||||
MS->fEof = FALSE;
|
||||
MS->fStart = (uint8_t *)uprv_malloc(MS->fSize);
|
||||
if(MS->fStart == NULL) {
|
||||
MS->fError = TRUE;
|
||||
@ -52,9 +53,10 @@ U_CAPI UMemoryStream * U_EXPORT2 uprv_mstrm_openBuffer(uint8_t *buffer, int32_t
|
||||
}
|
||||
MS->fReadOnly = TRUE;
|
||||
MS->fStart = buffer;
|
||||
MS->fPos = 0;
|
||||
MS->fPos = len;
|
||||
MS->fReadPos = 0;
|
||||
MS->fError = FALSE;
|
||||
MS->fEof = FALSE;
|
||||
return MS;
|
||||
}
|
||||
|
||||
@ -74,11 +76,16 @@ U_CAPI UBool U_EXPORT2 uprv_mstrm_error(UMemoryStream *MS){
|
||||
return MS->fError;
|
||||
}
|
||||
|
||||
U_CAPI UBool U_EXPORT2 uprv_mstrm_eof(UMemoryStream *MS){
|
||||
return MS->fEof;
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_read(UMemoryStream *MS, void* addr, int32_t len) {
|
||||
if(MS->fError == FALSE) {
|
||||
if(len + MS->fReadPos > MS->fPos) {
|
||||
len = MS->fPos - MS->fReadPos;
|
||||
MS->fError = TRUE;
|
||||
MS->fEof = TRUE;
|
||||
}
|
||||
|
||||
uprv_memcpy(addr, MS->fStart+MS->fReadPos, len);
|
||||
@ -89,13 +96,13 @@ U_CAPI int32_t U_EXPORT2 uprv_mstrm_read(UMemoryStream *MS, void* addr, int32_t
|
||||
}
|
||||
}
|
||||
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_write(UMemoryStream *MS, uint8_t *buffer, int32_t len){
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_write(UMemoryStream *MS, const uint8_t *buffer, int32_t len){
|
||||
if(MS->fError == FALSE) {
|
||||
if(MS->fReadOnly == FALSE) {
|
||||
if(len + MS->fPos > MS->fSize) {
|
||||
uint8_t *newstart = (uint8_t *)uprv_realloc(MS->fStart, 2*MS->fSize);
|
||||
uint8_t *newstart = (uint8_t *)uprv_realloc(MS->fStart, MS->fSize+len);
|
||||
if(newstart != NULL) {
|
||||
MS->fSize*=2;
|
||||
MS->fSize+=len;
|
||||
MS->fStart = newstart;
|
||||
} else {
|
||||
MS->fError = TRUE;
|
||||
|
@ -38,6 +38,7 @@ struct UMemoryStream{
|
||||
int32_t fReadPos;
|
||||
UBool fReadOnly;
|
||||
UBool fError;
|
||||
UBool fEof;
|
||||
};
|
||||
|
||||
U_CAPI UMemoryStream * U_EXPORT2 uprv_mstrm_openNew(int32_t size);
|
||||
@ -45,8 +46,9 @@ U_CAPI UMemoryStream * U_EXPORT2 uprv_mstrm_openBuffer(uint8_t *buffer, int32_t
|
||||
U_CAPI void U_EXPORT2 uprv_mstrm_close(UMemoryStream *MS);
|
||||
U_CAPI UBool U_EXPORT2 uprv_mstrm_setError(UMemoryStream *MS);
|
||||
U_CAPI UBool U_EXPORT2 uprv_mstrm_error(UMemoryStream *MS);
|
||||
U_CAPI UBool U_EXPORT2 uprv_mstrm_eof(UMemoryStream *MS);
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_read(UMemoryStream *MS, void* addr, int32_t len);
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_write(UMemoryStream *MS, uint8_t *buffer, int32_t len);
|
||||
U_CAPI int32_t U_EXPORT2 uprv_mstrm_write(UMemoryStream *MS, const uint8_t *buffer, int32_t len);
|
||||
U_CAPI uint8_t * U_EXPORT2 uprv_mstrm_getBuffer(UMemoryStream *MS, int32_t *len);
|
||||
|
||||
#endif /* _FILESTRM*/
|
||||
|
@ -1633,6 +1633,63 @@ UnicodeStringStreamer::streamIn(UnicodeString *s,
|
||||
s->fLength = newSize;
|
||||
}
|
||||
|
||||
void
|
||||
UnicodeStringStreamer::streamOut(const UnicodeString *s,
|
||||
UMemoryStream *os)
|
||||
{
|
||||
if(!uprv_mstrm_error(os)) {
|
||||
uprv_mstrm_write(os, (uint8_t*)&s->fLength, sizeof(s->fLength));
|
||||
}
|
||||
|
||||
const UChar *c = s->getArrayStart();
|
||||
const UChar *end = c + s->fLength;
|
||||
|
||||
while(c != end && ! uprv_mstrm_error(os)) {
|
||||
uprv_mstrm_write(os, (uint8_t*)c, sizeof(*c));
|
||||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
UnicodeStringStreamer::streamIn(UnicodeString *s,
|
||||
UMemoryStream *is)
|
||||
{
|
||||
int32_t newSize;
|
||||
|
||||
// handle error conditions
|
||||
if(uprv_mstrm_error(is) || uprv_mstrm_eof(is)) {
|
||||
s->setToBogus();
|
||||
return;
|
||||
}
|
||||
uprv_mstrm_read(is, (uint8_t *)&newSize, sizeof(int32_t));
|
||||
if((newSize < 0) || uprv_mstrm_error(is)
|
||||
|| ((newSize > 0) && uprv_mstrm_eof(is))) {
|
||||
s->setToBogus(); //error condition
|
||||
return;
|
||||
}
|
||||
|
||||
// clone s's array, if needed
|
||||
if(!s->cloneArrayIfNeeded(newSize, newSize, FALSE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UChar *c = s->getArrayStart();
|
||||
UChar *end = c + newSize;
|
||||
|
||||
while(c < end && ! (uprv_mstrm_error(is) || uprv_mstrm_eof(is))) {
|
||||
uprv_mstrm_read(is, (uint8_t *)c, sizeof(*c));
|
||||
c++;
|
||||
}
|
||||
|
||||
// couldn't read all chars
|
||||
if(c < end) {
|
||||
s->setToBogus();
|
||||
return;
|
||||
}
|
||||
|
||||
s->fLength = newSize;
|
||||
}
|
||||
|
||||
// console IO
|
||||
|
||||
#if U_IOSTREAM_SOURCE >= 198506
|
||||
|
@ -18,6 +18,7 @@
|
||||
#define UNISTRM_H
|
||||
|
||||
#include "filestrm.h"
|
||||
#include "umemstrm.h"
|
||||
#include "unicode/unistr.h"
|
||||
|
||||
|
||||
@ -26,6 +27,8 @@ class U_COMMON_API UnicodeStringStreamer
|
||||
public:
|
||||
static void streamIn(UnicodeString* string, FileStream* is);
|
||||
static void streamOut(const UnicodeString* string, FileStream* os);
|
||||
static void streamIn(UnicodeString* string, UMemoryStream* is);
|
||||
static void streamOut(const UnicodeString* string, UMemoryStream* os);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user