/* TODO: is this correct for all codepages? Should we just use \n and let the converter handle it? */ #if U_PLATFORM_USES_ONLY_WIN32_API staticconst char16_t DELIMITERS [] = { DELIM_CR, DELIM_LF, 0x0000 }; staticconst uint32_t DELIMITERS_LEN = 2; /* TODO: Default newline writing should be detected based upon the converter being used. */ #else staticconst char16_t DELIMITERS [] = { DELIM_LF, 0x0000 }; staticconst uint32_t DELIMITERS_LEN = 1; #endif
/* Now, copy any data over */
u_strncpy(f->fTranslit->buffer + f->fTranslit->length,
src,
*count);
f->fTranslit->length += *count;
/* Now, translit in place as much as we can */ if(flush == false)
{
textLength = f->fTranslit->length;
pos.contextStart = 0;
pos.contextLimit = textLength;
pos.start = 0;
pos.limit = textLength;
utrans_transIncrementalUChars(f->fTranslit->translit,
f->fTranslit->buffer, /* because we shifted */
&textLength,
f->fTranslit->capacity,
&pos,
&status);
/* now: start/limit point to the transliterated text */ /* Transliterated is [buffer..pos.start) */
*count = pos.start;
f->fTranslit->pos = pos.start;
f->fTranslit->length = pos.limit;
if (f->fFile == nullptr) { /* There is nothing to do. It's a string. */ return;
}
str = &f->str;
dataSize = static_cast<int32_t>(str->fLimit - str->fPos); if (f->fFileno == 0 && dataSize > 0) { /* Don't read from stdin too many times. There is still some data. */ return;
}
/* shift the buffer if it isn't empty */ if(dataSize != 0) {
u_memmove(f->fUCBuffer, str->fPos, dataSize); /* not accessing beyond memory */
}
/* record how much buffer space is available */
availLength = UFILE_UCHARBUFFER_SIZE - dataSize;
/* Determine the # of codepage bytes needed to fill our char16_t buffer */ /* weiv: if converter is nullptr, we use invariant converter with charwidth = 1)*/
maxCPBytes = availLength / (f->fConverter!=nullptr?(2*ucnv_getMinCharSize(f->fConverter)):1);
/* Read in the data to convert */ if (f->fFileno == 0) { /* Special case. Read from stdin one line at a time. */ char *retStr = fgets(charBuffer, ufmt_min(maxCPBytes, UFILE_CHARBUFFER_SIZE), f->fFile);
bytesRead = static_cast<int32_t>(retStr ? uprv_strlen(charBuffer) : 0);
} else { /* A normal file */
bytesRead = static_cast<int32_t>(fread(charBuffer, sizeof(char),
ufmt_min(maxCPBytes, UFILE_CHARBUFFER_SIZE),
f->fFile));
}
/* Set up conversion parameters */
status = U_ZERO_ERROR;
mySource = charBuffer;
mySourceEnd = charBuffer + bytesRead;
myTarget = f->fUCBuffer + dataSize;
bufferSize = UFILE_UCHARBUFFER_SIZE;
if(f->fConverter != nullptr) { /* We have a valid converter */ /* Perform the conversion */
ucnv_toUnicode(f->fConverter,
&myTarget,
f->fUCBuffer + bufferSize,
&mySource,
mySourceEnd,
nullptr, static_cast<UBool>(feof(f->fFile) != 0),
&status);
} else { /*weiv: do the invariant conversion */
u_charsToUChars(mySource, myTarget, bytesRead);
myTarget += bytesRead;
}
/* update the pointers into our array */
str->fPos = str->fBuffer;
str->fLimit = myTarget;
}
U_CAPI char16_t* U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
u_fgets(char16_t *s,
int32_t n,
UFILE *f)
{
int32_t dataSize;
int32_t count;
char16_t *alias; const char16_t *limit;
char16_t *sItr;
char16_t currDelim = 0;
u_localized_string *str;
if (n <= 0) { /* Caller screwed up. We need to write the null terminatior. */ return nullptr;
}
/* fill the buffer if needed */
str = &f->str; if (str->fPos >= str->fLimit) {
ufile_fill_uchar_buffer(f);
}
/* subtract 1 from n to compensate for the terminator */
--n;
/* determine the amount of data in the buffer */
dataSize = (int32_t)(str->fLimit - str->fPos);
/* if 0 characters were left, return 0 */ if (dataSize == 0) return nullptr;
/* otherwise, iteratively fill the buffer and copy */
count = 0;
sItr = s;
currDelim = 0; while (dataSize > 0 && count < n) {
alias = str->fPos;
/* Find how much to copy */ if (dataSize < (n - count)) {
limit = str->fLimit;
} else {
limit = alias + (n - count);
}
if (!currDelim) { /* Copy UChars until we find the first occurrence of a delimiter character */ while (alias < limit && !IS_FIRST_STRING_DELIMITER(*alias)) {
count++;
*(sItr++) = *(alias++);
} /* Preserve the newline */ if (alias < limit && IS_FIRST_STRING_DELIMITER(*alias)) { if (CAN_HAVE_COMBINED_STRING_DELIMITER(*alias)) {
currDelim = *alias;
} else {
currDelim = 1; /* This isn't a newline, but it's used to say that we should break later. We've checked all possible newline combinations even across buffer
boundaries. */
}
count++;
*(sItr++) = *(alias++);
}
} /* If we have a CRLF combination, preserve that too. */ if (alias < limit) { if (currDelim && IS_COMBINED_STRING_DELIMITER(currDelim, *alias)) {
count++;
*(sItr++) = *(alias++);
}
currDelim = 1; /* This isn't a newline, but it's used to say that we should break later. We've checked all possible newline combinations even across buffer
boundaries. */
}
/* update the current buffer position */
str->fPos = alias;
/* if we found a delimiter */ if (currDelim == 1) { /* break out */ break;
}
/* refill the buffer */
ufile_fill_uchar_buffer(f);
/* determine the amount of data in the buffer */
dataSize = (int32_t)(str->fLimit - str->fPos);
}
/* add the terminator and return s */
*sItr = 0x0000; return s;
}
*ch = U_EOF; /* if we have an available character in the buffer, return it */ if(f->str.fPos < f->str.fLimit){
*ch = *(f->str.fPos)++;
isValidChar = true;
} else { /* otherwise, fill the buffer and return the next character */ if(f->str.fPos >= f->str.fLimit) {
ufile_fill_uchar_buffer(f);
} if(f->str.fPos < f->str.fLimit) {
*ch = *(f->str.fPos)++;
isValidChar = true;
}
} return isValidChar;
}
U_CAPI char16_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
u_fgetc(UFILE *f)
{
char16_t ch;
ufile_getch(f, &ch); return ch;
}
/* Fill the buffer if it is empty */
str = &f->str; if (str->fPos + 1 >= str->fLimit) {
ufile_fill_uchar_buffer(f);
}
/* Get the next character in the buffer */ if (str->fPos < str->fLimit) {
*c32 = *(str->fPos)++; if (U_IS_LEAD(*c32)) { if (str->fPos < str->fLimit) {
char16_t c16 = *(str->fPos)++;
*c32 = U16_GET_SUPPLEMENTARY(*c32, c16);
isValidChar = true;
} else {
*c32 = U_EOF;
}
} else {
isValidChar = true;
}
}
return isValidChar;
}
U_CAPI UChar32 U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
u_fgetcx(UFILE *f)
{
UChar32 ch;
ufile_getch32(f, &ch); return ch;
}
U_CAPI UChar32 U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
u_fungetc(UChar32 ch,
UFILE *f)
{
u_localized_string *str;
str = &f->str;
/* if we're at the beginning of the buffer, sorry! */ if (str->fPos == str->fBuffer
|| (U_IS_LEAD(ch) && (str->fPos - 1) == str->fBuffer))
{
ch = U_EOF;
} else { /* otherwise, put the character back */ /* Remember, read them back on in the reverse order. */ if (U_IS_LEAD(ch)) { if (*--(str->fPos) != U16_TRAIL(ch)
|| *--(str->fPos) != U16_LEAD(ch))
{
ch = U_EOF;
}
} elseif (*--(str->fPos) != ch) {
ch = U_EOF;
}
} return ch;
}
/* determine the amount of data in the buffer */
dataSize = (int32_t)(str->fLimit - str->fPos); if (dataSize <= 0) { /* fill the buffer */
ufile_fill_uchar_buffer(f);
dataSize = (int32_t)(str->fLimit - str->fPos);
}
/* Make sure that we don't read too much */ if (dataSize > (count - read)) {
dataSize = count - read;
}
/* copy the current data in the buffer */
memcpy(chars + read, str->fPos, dataSize * sizeof(char16_t));
/* update number of items read */
read += dataSize;
/* update the current buffer position */
str->fPos += dataSize;
} while (dataSize != 0 && read < count);
return read;
} #endif
Messung V0.5
¤ Dauer der Verarbeitung: 0.2 Sekunden
(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.