aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/func.c36
-rw-r--r--src/printf.c20
-rw-r--r--src/sqliteInt.h1
-rw-r--r--src/utf.c29
4 files changed, 35 insertions, 51 deletions
diff --git a/src/func.c b/src/func.c
index 124dabe31..d8c812759 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1150,34 +1150,6 @@ void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue, int bEscape){
}
/*
-** Write a single UTF8 character whose value if v into the
-** buffer starting at zOut. Return the number of bytes needed
-** to encode that character.
-*/
-static int appendOneUtf8Char(char *zOut, u32 v){
- if( v<0x00080 ){
- zOut[0] = (u8)(v & 0xff);
- return 1;
- }
- if( v<0x00800 ){
- zOut[0] = 0xc0 + (u8)((v>>6) & 0x1f);
- zOut[1] = 0x80 + (u8)(v & 0x3f);
- return 2;
- }
- if( v<0x10000 ){
- zOut[0] = 0xe0 + (u8)((v>>12) & 0x0f);
- zOut[1] = 0x80 + (u8)((v>>6) & 0x3f);
- zOut[2] = 0x80 + (u8)(v & 0x3f);
- return 3;
- }
- zOut[0] = 0xf0 + (u8)((v>>18) & 0x07);
- zOut[1] = 0x80 + (u8)((v>>12) & 0x3f);
- zOut[2] = 0x80 + (u8)((v>>6) & 0x3f);
- zOut[3] = 0x80 + (u8)(v & 0x3f);
- return 4;
-}
-
-/*
** Return true if z[] begins with N hexadecimal digits, and write
** a decoding of those digits into *pVal. Or return false if any
** one of the first N characters in z[] is not a hexadecimal digit.
@@ -1248,19 +1220,19 @@ static void unistrFunc(
}else if( sqlite3Isxdigit(zIn[i+1]) ){
if( !isNHex(&zIn[i+1], 4, &v) ) goto unistr_error;
i += 5;
- j += appendOneUtf8Char(&zOut[j], v);
+ j += sqlite3AppendOneUtf8Character(&zOut[j], v);
}else if( zIn[i+1]=='+' ){
if( !isNHex(&zIn[i+2], 6, &v) ) goto unistr_error;
i += 8;
- j += appendOneUtf8Char(&zOut[j], v);
+ j += sqlite3AppendOneUtf8Character(&zOut[j], v);
}else if( zIn[i+1]=='u' ){
if( !isNHex(&zIn[i+2], 4, &v) ) goto unistr_error;
i += 6;
- j += appendOneUtf8Char(&zOut[j], v);
+ j += sqlite3AppendOneUtf8Character(&zOut[j], v);
}else if( zIn[i+1]=='U' ){
if( !isNHex(&zIn[i+2], 8, &v) ) goto unistr_error;
i += 10;
- j += appendOneUtf8Char(&zOut[j], v);
+ j += sqlite3AppendOneUtf8Character(&zOut[j], v);
}else{
goto unistr_error;
}
diff --git a/src/printf.c b/src/printf.c
index 2b4ccf259..30c4ec605 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -673,25 +673,7 @@ void sqlite3_str_vappendf(
}
}else{
unsigned int ch = va_arg(ap,unsigned int);
- if( ch<0x00080 ){
- buf[0] = ch & 0xff;
- length = 1;
- }else if( ch<0x00800 ){
- buf[0] = 0xc0 + (u8)((ch>>6)&0x1f);
- buf[1] = 0x80 + (u8)(ch & 0x3f);
- length = 2;
- }else if( ch<0x10000 ){
- buf[0] = 0xe0 + (u8)((ch>>12)&0x0f);
- buf[1] = 0x80 + (u8)((ch>>6) & 0x3f);
- buf[2] = 0x80 + (u8)(ch & 0x3f);
- length = 3;
- }else{
- buf[0] = 0xf0 + (u8)((ch>>18) & 0x07);
- buf[1] = 0x80 + (u8)((ch>>12) & 0x3f);
- buf[2] = 0x80 + (u8)((ch>>6) & 0x3f);
- buf[3] = 0x80 + (u8)(ch & 0x3f);
- length = 4;
- }
+ length = sqlite3AppendOneUtf8Character(buf, ch);
}
if( precision>1 ){
i64 nPrior = 1;
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 5e3ec4dad..a1cfe8920 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -5143,6 +5143,7 @@ FuncDef *sqlite3FunctionSearch(int,const char*);
void sqlite3InsertBuiltinFuncs(FuncDef*,int);
FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8);
void sqlite3QuoteValue(StrAccum*,sqlite3_value*,int);
+int sqlite3AppendOneUtf8Character(char*, u32);
void sqlite3RegisterBuiltinFunctions(void);
void sqlite3RegisterDateTimeFunctions(void);
void sqlite3RegisterJsonFunctions(void);
diff --git a/src/utf.c b/src/utf.c
index c934bb234..57700bf20 100644
--- a/src/utf.c
+++ b/src/utf.c
@@ -106,6 +106,35 @@ static const unsigned char sqlite3Utf8Trans1[] = {
}
/*
+** Write a single UTF8 character whose value is v into the
+** buffer starting at zOut. zOut must be sized to hold at
+** least for bytes. Return the number of bytes needed
+** to encode the new character.
+*/
+int sqlite3AppendOneUtf8Character(char *zOut, u32 v){
+ if( v<0x00080 ){
+ zOut[0] = (u8)(v & 0xff);
+ return 1;
+ }
+ if( v<0x00800 ){
+ zOut[0] = 0xc0 + (u8)((v>>6) & 0x1f);
+ zOut[1] = 0x80 + (u8)(v & 0x3f);
+ return 2;
+ }
+ if( v<0x10000 ){
+ zOut[0] = 0xe0 + (u8)((v>>12) & 0x0f);
+ zOut[1] = 0x80 + (u8)((v>>6) & 0x3f);
+ zOut[2] = 0x80 + (u8)(v & 0x3f);
+ return 3;
+ }
+ zOut[0] = 0xf0 + (u8)((v>>18) & 0x07);
+ zOut[1] = 0x80 + (u8)((v>>12) & 0x3f);
+ zOut[2] = 0x80 + (u8)((v>>6) & 0x3f);
+ zOut[3] = 0x80 + (u8)(v & 0x3f);
+ return 4;
+}
+
+/*
** Translate a single UTF-8 character. Return the unicode value.
**
** During translation, assume that the byte that zTerm points