ICU-410 add u_fgetcx (unescaping u_fgetc)
X-SVN-Rev: 1898
This commit is contained in:
parent
5e9d055754
commit
81f0a973af
@ -324,6 +324,22 @@ u_fgets(UFILE *f,
|
||||
U_CAPI UChar U_EXPORT2
|
||||
u_fgetc(UFILE *f);
|
||||
|
||||
/**
|
||||
* Read a UChar from a UFILE and process escape sequences. If the
|
||||
* next character is not a backslash, this is the same as calling
|
||||
* u_fgetc(). If it is, then additional characters comprising the
|
||||
* escape sequence will be read from the UFILE, parsed, and the
|
||||
* resultant UChar returned. Ill-formed escape sequences return
|
||||
* U+FFFFFFFF.
|
||||
* @param f The UFILE from which to read.
|
||||
* @return The UChar value read, or U+FFFF if no character was
|
||||
* available, or U+FFFFFFFF if an ill-formed escape sequence was
|
||||
* encountered.
|
||||
* @see u_unescape()
|
||||
*/
|
||||
U_CAPI UChar32 U_EXPORT2
|
||||
u_fgetcx(UFILE *f);
|
||||
|
||||
/**
|
||||
* Unget a UChar from a UFILE.
|
||||
* If this function is not the first to operate on <TT>f</TT> after a call
|
||||
|
@ -281,6 +281,57 @@ u_fgetc(UFILE *f)
|
||||
}
|
||||
}
|
||||
|
||||
/* u_unescapeAt() callback to return a UChar from a UFILE */
|
||||
static UChar _charAt(int32_t offset, void *context) {
|
||||
return ((UFILE*) context)->fUCPos[offset];
|
||||
}
|
||||
|
||||
/* Read a UChar from a UFILE and process escape sequences */
|
||||
UChar32
|
||||
u_fgetcx(UFILE *f) {
|
||||
int32_t length;
|
||||
int32_t offset;
|
||||
UChar32 c32;
|
||||
UChar c16;
|
||||
|
||||
/* Fill the buffer if it is empty */
|
||||
if (f->fUCPos >= f->fUCLimit) {
|
||||
ufile_fill_uchar_buffer(f);
|
||||
}
|
||||
|
||||
/* Get the next character in the buffer */
|
||||
if (f->fUCPos < f->fUCLimit) {
|
||||
c16 = *(f->fUCPos)++;
|
||||
} else {
|
||||
c16 = U_EOF;
|
||||
}
|
||||
|
||||
/* If it isn't a backslash, return it */
|
||||
if (c16 != 0x005C /*'\\'*/) {
|
||||
return c16;
|
||||
}
|
||||
|
||||
/* Determine the amount of data in the buffer */
|
||||
length = f->fUCLimit - f->fUCPos;
|
||||
|
||||
/* The longest escape sequence is \Uhhhhhhhh; make sure
|
||||
we have at least that many characters */
|
||||
if (length < 10) {
|
||||
/* fill the buffer */
|
||||
ufile_fill_uchar_buffer(f);
|
||||
length = f->fUCLimit - f->fUCPos;
|
||||
}
|
||||
|
||||
/* Process the escape */
|
||||
offset = 0;
|
||||
c32 = u_unescapeAt(_charAt, &offset, length, (void*)f);
|
||||
|
||||
/* Update the current buffer position */
|
||||
f->fUCPos += offset;
|
||||
|
||||
return c32;
|
||||
}
|
||||
|
||||
UChar
|
||||
u_fungetc(UChar c,
|
||||
UFILE *f)
|
||||
|
Loading…
Reference in New Issue
Block a user