/* unread the bytes beyond what was consumed for U+FEFF */
T_FileStream_rewind(in); if (*signatureLength > 0) {
T_FileStream_read(in, start, *signatureLength);
}
if(*cp==nullptr){
*conv =nullptr; returnfalse;
}
/* open the converter for the detected Unicode charset */
*conv = ucnv_open(*cp,error);
memcpy(postContext,source,stop-start); /* null terminate the buffer */
postContext[stop-start] = 0;
if(buf->showWarning ==true){ /* print out the context */
fprintf(stderr,"\tPre-context: %s\n",preContext);
fprintf(stderr,"\tContext: %s\n",context);
fprintf(stderr,"\tPost-context: %s\n", postContext);
}
/* reset the converter */
ucnv_reset(buf->conv);
/* set the call back to substitute * and restart conversion
*/
ucnv_setToUCallBack(buf->conv,
UCNV_TO_U_CALLBACK_SUBSTITUTE,
toUNewContext,
&toUOldAction,
(constvoid**)&toUOldContext,
&error1);
/* u_unescapeAt() callback to return a char16_t*/ static char16_t U_CALLCONV
_charAt(int32_t offset, void *context) { returnstatic_cast<UCHARBUF*>(context)->currentPos[offset];
}
/* getc and escape it */
U_CAPI int32_t U_EXPORT2
ucbuf_getcx32(UCHARBUF* buf,UErrorCode* error) {
int32_t length;
int32_t offset;
UChar32 c32,c1,c2; if(error==nullptr || U_FAILURE(*error)){ returnfalse;
} /* Fill the buffer if it is empty */ if (buf->currentPos >=buf->bufLimit-2) {
ucbuf_fillucbuf(buf,error);
}
/* Get the next character in the buffer */ if (buf->currentPos < buf->bufLimit) {
c1 = *(buf->currentPos)++;
} else {
c1 = U_EOF;
}
c2 = *(buf->currentPos);
/* If it isn't a backslash, return it */ if (c1 != 0x005C) { return c1;
}
/* Determine the amount of data in the buffer */
length = (int32_t)(buf->bufLimit - buf->currentPos);
/* The longest escape sequence is \Uhhhhhhhh; make sure
we have at least that many characters */ if (length < 10) {
/* fill the buffer */
ucbuf_fillucbuf(buf,error);
length = (int32_t)(buf->bufLimit - buf->buffer);
}
/* Process the escape */
offset = 0;
c32 = u_unescapeAt(_charAt, &offset, length, (void*)buf);
/* check if u_unescapeAt unescaped and converted * to c32 or not
*/ if(c32==(UChar32)0xFFFFFFFF){ if(buf->showWarning) { char context[CONTEXT_LEN+1];
int32_t len = CONTEXT_LEN; if(length < len) {
len = length;
}
context[len]= 0 ; /* null terminate the buffer */
u_UCharsToChars( buf->currentPos, context, len);
fprintf(stderr,"Bad escape: [%c%s]...\n", (int)c1, context);
}
*error= U_ILLEGAL_ESCAPE_SEQUENCE; return c1;
}elseif(c32!=c2 || (c32==0x0075 && c2==0x0075 && c1==0x005C) /* for \u0075 c2=0x0075 and c32==0x0075*/){ /* Update the current buffer position */
buf->currentPos += offset;
}else{ /* unescaping failed so we just return * c1 and not consume the buffer * this is useful for rules with escapes * in resource bundles * eg: \' \\ \"
*/ return c1;
}
/* TODO: this method will fail if at the * beginning of buffer and the uchar to unget * is from the previous buffer. Need to implement * system to take care of that situation.
*/
U_CAPI void U_EXPORT2
ucbuf_ungetc(int32_t c,UCHARBUF* buf){ /* decrement currentPos pointer * if not at the beginning of buffer
*/ if(buf->currentPos!=buf->buffer){ if(*(buf->currentPos-1)==c){
buf->currentPos--;
} else { /* ungetc failed - did not match. */
}
} else { /* ungetc failed - beginning of buffer. */
}
}
/* frees the resources of char16_t* buffer */ staticvoid
ucbuf_closebuf(UCHARBUF* buf){
uprv_free(buf->buffer);
buf->buffer = nullptr;
}
/* close the buf and release resources*/
U_CAPI void U_EXPORT2
ucbuf_close(UCHARBUF* buf){ if(buf!=nullptr){ if(buf->conv){
ucnv_close(buf->conv);
}
T_FileStream_close(buf->in);
ucbuf_closebuf(buf);
uprv_free(buf);
}
}
target[0] = '\0'; /* * append the input dir to openFileName if the first char in * filename is not file separation char and the last char input directory is not '.'. * This is to support : * genrb -s. /home/icu/data * genrb -s. icu/data * The user cannot mix notations like * genrb -s. /icu/data --- the absolute path specified. -s redundant * user should use * genrb -s. icu/data --- start from CWD and look in icu/data dir
*/ if( (fileName[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')){
uprv_strcpy(target, inputDir);
target[dirlen] = U_FILE_SEP_CHAR;
}
target[dirlen + 1] = '\0';
} else {
requiredLen = dirlen + filelen + 1; if((*len < requiredLen) || target==nullptr){
*len = requiredLen;
*status = U_BUFFER_OVERFLOW_ERROR; return nullptr;
}
uprv_strcpy(target, inputDir);
}
uprv_strcat(target, fileName); return target;
} /* * Unicode TR 13 says any of the below chars is * a new line char in a readline function in addition * to CR+LF combination which needs to be * handled separately
*/ static UBool ucbuf_isCharNewLine(char16_t c){ switch(c){ case 0x000A: /* LF */ case 0x000D: /* CR */ case 0x000C: /* FF */ case 0x0085: /* NEL */ case 0x2028: /* LS */ case 0x2029: /* PS */ returntrue; default: returnfalse;
}
}
U_CAPI const char16_t* U_EXPORT2
ucbuf_readline(UCHARBUF* buf,int32_t* len,UErrorCode* err){
char16_t* temp = buf->currentPos;
char16_t* savePos =nullptr;
char16_t c=0x0000; if(buf->isBuffered){ /* The input is buffered we have to do more * for returning a pointer U_TRUNCATED_CHAR_FOUND
*/ for(;;){
c = *temp++; if(buf->remaining==0){ return nullptr; /* end of file is reached return nullptr */
} if(temp>=buf->bufLimit && buf->currentPos == buf->buffer){
*err= U_TRUNCATED_CHAR_FOUND; return nullptr;
}else{
ucbuf_fillucbuf(buf,err); if(U_FAILURE(*err)){ return nullptr;
}
} /* * According to TR 13 readLine functions must interpret * CR, CR+LF, LF, NEL, PS, LS or FF as line seperators
*/ /* Windows CR LF */ if(c ==0x0d && temp <= buf->bufLimit && *temp == 0x0a ){
*len = (int32_t)(temp++ - buf->currentPos);
savePos = buf->currentPos;
buf->currentPos = temp; return savePos;
} /* else */
if (temp>=buf->bufLimit|| ucbuf_isCharNewLine(c)){ /* Unipad inserts 2028 line separators! */
*len = (int32_t)(temp - buf->currentPos);
savePos = buf->currentPos;
buf->currentPos = temp; return savePos;
}
}
}else{ /* we know that all input is read into the internal * buffer so we can safely return pointers
*/ for(;;){
c = *temp++;
if(buf->currentPos==buf->bufLimit){ return nullptr; /* end of file is reached return nullptr */
} /* Windows CR LF */ if(c ==0x0d && temp <= buf->bufLimit && *temp == 0x0a ){
*len = (int32_t)(temp++ - buf->currentPos);
savePos = buf->currentPos;
buf->currentPos = temp; return savePos;
} /* else */ if (temp>=buf->bufLimit|| ucbuf_isCharNewLine(c)) { /* Unipad inserts 2028 line separators! */
*len = (int32_t)(temp - buf->currentPos);
savePos = buf->currentPos;
buf->currentPos = temp; return savePos;
}
}
} /* not reached */ /* A compiler warning will appear if all paths don't contain a return statement. */ /* return nullptr;*/
} #endif
Messung V0.5
¤ 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.0.32Bemerkung:
(vorverarbeitet)
¤
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.