diff options
author | George Hazan <george.hazan@gmail.com> | 2014-04-01 14:58:49 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-04-01 14:58:49 +0000 |
commit | 024c7fb409dc9b0c921a41a89a411496a17b0f70 (patch) | |
tree | cc68c2501bbbbfb9975c743b2daf1a4674ece016 /plugins/CryptoPP/src/utf8.cpp | |
parent | 41b55005fb074c35e5a62f8e8155c4be6edc2f22 (diff) |
CryptoPP: code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@8813 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/src/utf8.cpp')
-rw-r--r-- | plugins/CryptoPP/src/utf8.cpp | 126 |
1 files changed, 63 insertions, 63 deletions
diff --git a/plugins/CryptoPP/src/utf8.cpp b/plugins/CryptoPP/src/utf8.cpp index 2bd1a8f26b..e6b9602161 100644 --- a/plugins/CryptoPP/src/utf8.cpp +++ b/plugins/CryptoPP/src/utf8.cpp @@ -3,34 +3,33 @@ LPSTR szOut = NULL;
LPWSTR wszOut = NULL;
-LPSTR __cdecl utf8encode(LPCWSTR str) {
-
-// LPSTR szOut;
+LPSTR __cdecl utf8encode(LPCWSTR str)
+{
LPWSTR wszTemp, w;
int len, i;
-
- if (str == NULL)
- return NULL;
+
+ if (str == NULL)
+ return NULL;
wszTemp = (LPWSTR)str;
len = 0;
- for (w=wszTemp; *w; w++) {
+ for (w = wszTemp; *w; w++) {
if (*w < 0x0080) len++;
else if (*w < 0x0800) len += 2;
else len += 3;
}
- SAFE_FREE(szOut);
- if ((szOut = (LPSTR) malloc(len + 1)) == NULL)
+ SAFE_FREE(szOut);
+ if ((szOut = (LPSTR)malloc(len + 1)) == NULL)
return NULL;
i = 0;
- for (w=wszTemp; *w; w++) {
+ for (w = wszTemp; *w; w++) {
if (*w < 0x0080)
- szOut[i++] = (BYTE) *w;
+ szOut[i++] = (BYTE)*w;
else if (*w < 0x0800) {
- szOut[i++] = 0xc0 | (((*w) >> 6) &0x3f);
+ szOut[i++] = 0xc0 | (((*w) >> 6) & 0x3f);
szOut[i++] = 0x80 | ((*w) & 0x3f);
}
else {
@@ -43,18 +42,19 @@ LPSTR __cdecl utf8encode(LPCWSTR str) { return szOut;
}
-LPWSTR __cdecl utf8decode(LPCSTR str) {
+LPWSTR __cdecl utf8decode(LPCSTR str)
+{
int i, len;
LPSTR p;
-// LPWSTR wszOut;
+ // LPWSTR wszOut;
if (str == NULL) return NULL;
- len = strlen(str)+1;
+ len = strlen(str) + 1;
SAFE_FREE(wszOut);
- if ((wszOut = (LPWSTR) malloc(len*sizeof(WCHAR))) == NULL)
+ if ((wszOut = (LPWSTR)malloc(len*sizeof(WCHAR))) == NULL)
return NULL;
p = (LPSTR)str;
i = 0;
@@ -83,9 +83,10 @@ LPWSTR __cdecl utf8decode(LPCSTR str) { // Returns true if the buffer only contains 7-bit characters.
-int __cdecl is_7bit_string(LPCSTR str) {
- while( *str ) {
- if ( *str & 0x80 ) {
+int __cdecl is_7bit_string(LPCSTR str)
+{
+ while (*str) {
+ if (*str & 0x80) {
return FALSE;
break;
}
@@ -98,52 +99,51 @@ int __cdecl is_7bit_string(LPCSTR str) { //Copyright (C) 2001, 2002 Peter Verthez
//under GNU LGPL
-int __cdecl is_utf8_string(LPCSTR str) {
- int expect_bytes = 0;
-
- if (!str) return 0;
-
- while (*str) {
- if ((*str & 0x80) == 0) {
- /* Looks like an ASCII character */
- if (expect_bytes)
- /* byte of UTF-8 character expected */
- return 0;
- else {
- /* OK, ASCII character expected */
- str++;
- }
- }
- else {
- /* Looks like byte of an UTF-8 character */
- if (expect_bytes) {
- /* expect_bytes already set: first byte of UTF-8 char already seen */
- if ((*str & 0xC0) == 0x80) {
- /* OK, next byte of UTF-8 character */
- /* Decrement number of expected bytes */
- expect_bytes--;
- str++;
+int __cdecl is_utf8_string(LPCSTR str)
+{
+ int expect_bytes = 0;
+
+ if (!str) return 0;
+
+ while (*str) {
+ if ((*str & 0x80) == 0) {
+ /* Looks like an ASCII character */
+ if (expect_bytes)
+ /* byte of UTF-8 character expected */
+ return 0;
+ else {
+ /* OK, ASCII character expected */
+ str++;
+ }
}
else {
- /* again first byte ?!?! */
- return 0;
+ /* Looks like byte of an UTF-8 character */
+ if (expect_bytes) {
+ /* expect_bytes already set: first byte of UTF-8 char already seen */
+ if ((*str & 0xC0) == 0x80) {
+ /* OK, next byte of UTF-8 character */
+ /* Decrement number of expected bytes */
+ expect_bytes--;
+ str++;
+ }
+ else {
+ /* again first byte ?!?! */
+ return 0;
+ }
+ }
+ else {
+ /* First byte of the UTF-8 character */
+ /* count initial one bits and set expect_bytes to 1 less */
+ char ch = *str;
+ while (ch & 0x80) {
+ expect_bytes++;
+ ch = (ch & 0x7f) << 1;
+ }
+ expect_bytes--;
+ str++;
+ }
}
- }
- else {
- /* First byte of the UTF-8 character */
- /* count initial one bits and set expect_bytes to 1 less */
- char ch = *str;
- while (ch & 0x80) {
- expect_bytes++;
- ch = (ch & 0x7f) << 1;
- }
- expect_bytes--;
- str++;
- }
- }
- }
+ }
- return (expect_bytes == 0);
+ return (expect_bytes == 0);
}
-
-// EOF
|