CStringA UrlDecode(CStringA str, bool fRaw) { str.Replace("&", "&"); CHAR* s = str.GetBuffer(str.GetLength()); CHAR* e = s + str.GetLength(); CHAR* s1 = s; CHAR* s2 = s; while(s1 < e) { CHAR s11 = (s1 < e-1) ? (__isascii(s1[1]) && isupper(s1[1]) ? tolower(s1[1]) : s1[1]) : 0; CHAR s12 = (s1 < e-2) ? (__isascii(s1[2]) && isupper(s1[2]) ? tolower(s1[2]) : s1[2]) : 0; if(*s1 == '%' && s1 < e-2 && (s1[1] >= '0' && s1[1] <= '9' || s11 >= 'a' && s11 <= 'f') && (s1[2] >= '0' && s1[2] <= '9' || s12 >= 'a' && s12 <= 'f')) { s1[1] = s11; s1[2] = s12; *s2 = 0; if(s1[1] >= '0' && s1[1] <= '9') *s2 |= s1[1]-'0'; else if(s1[1] >= 'a' && s1[1] <= 'f') *s2 |= s1[1]-'a'+10; *s2 <<= 4; if(s1[2] >= '0' && s1[2] <= '9') *s2 |= s1[2]-'0'; else if(s1[2] >= 'a' && s1[2] <= 'f') *s2 |= s1[2]-'a'+10; s1 += 2; } else { *s2 = *s1 == '+' && !fRaw ? ' ' : *s1; } s1++; s2++; } str.ReleaseBuffer(s2 - s); return str; }
void XMLrd::SampConvert(char *str) { int i; for (i = 0; str[i] != '\0'; i++) { if (__isascii(str[i])) { #if 0 if (str[i] == '\\') { // skip over hex char codes if (str[++i] == 'x') i += 3; } else #endif if (SampStart) { if (str[i] == ' ') { SampStart = false; SampStartPos = i; SampEnd = true; } } else if (SampEnd) { if (strchr(" ,.?/!;:)}]=", str[i])) { if (i <= (SampStartPos + SampWordMin)) { SampEnd = false; SampStart = true; } else { assert(SampListLen); int len = SampListLen[SampListNum]; bool uc = isupper(str[SampStartPos + 1]) ? true : false; memmove(&str[SampStartPos + 1 + len], &str[i], strlen(&str[i]) + 1); memcpy(&str[SampStartPos + 1], SampList[SampListNum], len); if (uc) str[SampStartPos + 1] = toupper(*SampList[SampListNum]); if (++SampListNum >= SampListCount) SampListNum = 0; SampEnd = false; SampDelay = 0; } } } else if (++SampDelay >= SampDelayLimit) SampStart = true; } } if (SampEnd) { SampEnd = false; SampStart = true; } }
int json_add_value(log_t *log, const _TCHAR *key, const _TCHAR *value) { int i; if(((struct json_data*)log->moduleData)->followingKeyVal == 1) { _ftprintf(log->file, _T(",")); } _ftprintf(log->file, _T("\n%*s\"%s\": \""), log->indentLevel * 3, _T(" "), key); for(i=0; value[i]; i++) { switch(value[i]) { case _T('"'): _ftprintf(log->file, _T("%s"), _T("\"")); break; case _T('\\'): _ftprintf(log->file, _T("%s"), _T("\\\\")); break; case _T('/'): _ftprintf(log->file, _T("%s"), _T("\\/")); break; case _T('\b'): _ftprintf(log->file, _T("%s"), _T("\\b")); break; case _T('\f'): _ftprintf(log->file, _T("%s"), _T("\\f")); break; case _T('\n'): _ftprintf(log->file, _T("%s"), _T("\\n")); break; case _T('\r'): _ftprintf(log->file, _T("%s"), _T("\\r")); break; case _T('\t'): _ftprintf(log->file, _T("%s"), _T("\\t")); break; default: if(__isascii(value[i])) { _ftprintf(log->file, _T("%c"), value[i]); } else { _ftprintf(log->file, _T("%04d"), value[i]); } } } _ftprintf(log->file, _T("\"")); ((struct json_data*)log->moduleData)->followingKeyVal = 1; return 0; }
// ----------------------------------------------------------------------------- // CATBase::IsAscii(const char*,const unsigned int) // ----------------------------------------------------------------------------- bool CATBase::IsAscii( const char* pInput, const unsigned int iLength ) { LOG_LOW_FUNC_ENTRY("CATBase::IsAscii"); bool bRet = true; const char* pPoint = pInput; for( unsigned int i = 0 ; i < iLength ; i++) { if( !__isascii(*pPoint) ) { bRet = false; break; } pPoint++; } return bRet; }
/* ** ** [func] - mbtowc. ** [desc] - attempts to convert the s multi-byte character to the corresponding ** wide-character. if able to convert the s multi-byte character to the ** corresponding wide-character then stores the resulitng wide-character ** to the memory pointed to by wc and returns the number of bytes for ** the multi-byte character. else if the multi-byte character is '\0' ** then returns 1. else returns -1. ** [entr] - wchar_t *wc; the source wide-character string pointer. ** const char *s; the pointer to the destination multi-byte string buffer. ** size_t n; the number of bytes to check. ** [exit] - int; the number of bytes for mb char. else 1 if mb char is '\0'. else -1. ** [prec] - wc is a valid wchar_t pointer and s is a valid string pointer. ** [post] - the memory pointed to by wc is modified. ** */ int mbtowc(wchar_t *wc, const char *s, size_t n) { int ret = -1; const mbchar_t *mb; wchar_t i; /* test for NULL source string pointer. */ if (s != NULL) { if (*s != '\0') { /* test if the multi-byte conversion table has initialized. */ if ((_ctype_info->mbchar == NULL) || (_ctype_info->mbchar->chars == NULL)) { if (wc != NULL) { *wc = (wchar_t)*s; ret = 1; } } else { /* search only up to maximum current multi-byte bytes. */ if (n > MB_CUR_MAX) n = MB_CUR_MAX; for (i = 0; i < WCHAR_MAX; ++i) { /* process the curent multi-byte character. */ mb = &_ctype_info->mbchar->chars[i]; if ((i == (wchar_t)EOF) || (i == (wchar_t)'\0')) continue; else if (__isascii(i)) continue; else if ((mb->string == NULL) || (mb->len == 0)) continue; else if (mb->len > n) continue; else if (strncmp(mb->string, s, mb->len) == 0) { if (wc != NULL) *wc = i; __stdlib_mb_shift += mb->shift; ret = mb->len; break; } } } } else ret = 0; } else ret = (__stdlib_mb_shift != 0); return (ret); }
/* Long-term passwords are computed over the key: key = MD5(username ":"******":" SASLprep(password)) Per RFC 5389 S 15.4 */ int nr_stun_compute_lt_message_integrity_password(const char *username, const char *realm, Data *password, Data *hmac_key) { char digest_input[1000]; int i; int r, _status; size_t len; /* First check that the password is ASCII. We are supposed to SASLprep but we don't support this yet TODO([email protected]): Add SASLprep for password. */ for (i=0; i<password->len; i++) { if (!__isascii(password->data[i])) ABORT(R_BAD_DATA); } if (hmac_key->len < 16) ABORT(R_BAD_ARGS); snprintf(digest_input, sizeof(digest_input), "%s:%s:", username, realm); if ((sizeof(digest_input) - strlen(digest_input)) < password->len) ABORT(R_BAD_DATA); len = strlen(digest_input); memcpy(digest_input + len, password->data, password->len); if (r=nr_crypto_md5((UCHAR *)digest_input, len + password->len, hmac_key->data)) ABORT(r); hmac_key->len=16; _status=0; abort: return(_status); }
int isascii(int c) { return __isascii(c); /* locale-independent */ }
int __XL_NPP(isascii)(int c) { return __isascii(c); /* locale-independent */ }
void CLyricsDlg::LoadFromFile(HWND hDlg) { OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); wchar_t strFile[260]; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hDlg; ofn.lpstrFilter = L"Fișiere Text (*.txt)\0*.txt\0\0"; ofn.nFilterIndex = 1; ofn.lpstrFile = strFile; ofn.lpstrFile[0] = 0; ofn.nMaxFile = sizeof(strFile); ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // Display the Open dialog box. if (GetOpenFileName(&ofn)==TRUE) { HANDLE hFile = CreateFile(ofn.lpstrFile, GENERIC_READ, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL); byte xch[2], ch; string str; byte dUnicode = 0;//0 = ANSI, 1 = UTF-8, 2 = UTF-16(FF FE) 3 = UTF-16BE (FE FF) DWORD dwRead; if (0 == ReadFile(hFile, xch, 2, &dwRead, 0)) { MessageBoxA(hDlg, "Error! The file could not be read!", "Error!", MB_ICONERROR); #ifdef _DEBUG DebugBreak(); #endif return; } if (xch[0]==0xFF && xch[1]==0xFE) dUnicode = 2; else if (xch[0]==0xFE && xch[1]==0xFF) dUnicode = 3; else if (!( __isascii(xch[0]) && __isascii(xch[1]) || iswascii(MAKEWORD(xch[0], xch[1])))) { if (MessageBoxW(hDlg, L"Fișierul ar putea fi afișat incorect datorită codării. Vrei să continui așa?", L"Problemă de codificare", MB_ICONEXCLAMATION | MB_YESNO) == IDNO) return; } if (!dUnicode) SetFilePointer(hFile, 0, 0, FILE_BEGIN); DWORD dwSize = GetFileSize(hFile, 0); byte* buffer = new byte[dwSize]; ReadFile(hFile, buffer, dwSize, &dwRead, 0); if (dUnicode == 2)//FF FE { // while (ReadFile(hFile, xch, 2, &dwRead, 0) ) for (int i = 0; i < dwSize-1; i += 2) { xch[0] = buffer[i]; xch[1] = buffer[i+1]; if (xch[1]==0 && xch[0]!='\r') str += xch[0]; } } else if (dUnicode == 3)//FE FF { for (int i = 0; i < dwSize-1; i += 2) { xch[0] = buffer[i]; xch[1] = buffer[i+1]; if (xch[0]==0 && xch[1]!='\r') str += xch[1]; } } else { for (int i = 0; i < dwSize; i++) // while (ReadFile(hFile, &ch, 1, &dwRead, 0)) { ch = buffer[i]; if (dwRead == 0) break; if (ch!='\r') str += ch; } } delete[] buffer; CloseHandle(hFile); SetList(hDlg, str); } }
int isascii (int c) { return __isascii (c); }
PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size_t *out_len) {/*{{{*/ wchar_t *ret = NULL; const char *idx = in, *end; assert(in && in_len ? in[in_len] == '\0' : 1); if (!in) { SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER); return NULL; } else if (0 == in_len) { /* Not binary safe. */ in_len = strlen(in); if (in_len > (size_t)INT_MAX) { SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER); return NULL; } } end = in + in_len; while (idx != end) { if (!__isascii(*idx) && '\0' != *idx) { break; } idx++; } if (idx == end) { size_t i = 0; int k = 0; wchar_t *ret_idx; ret = malloc((in_len+1)*sizeof(wchar_t)); if (!ret) { SET_ERRNO_FROM_WIN32_CODE(ERROR_OUTOFMEMORY); return NULL; } ret_idx = ret; do { k = _snwprintf(ret_idx, in_len - i, L"%.*hs", (int)(in_len - i), in); if (-1 == k) { free(ret); SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER); return NULL; } i += k + 1; if (i < in_len) { /* Advance as this seems to be a string with \0 in it. */ in += k + 1; ret_idx += k + 1; } } while (i < in_len); ret[in_len] = L'\0'; assert(ret ? wcslen(ret) == in_len : 1); if (PHP_WIN32_CP_IGNORE_LEN_P != out_len) { *out_len = in_len; } } else { if (PHP_WIN32_CP_IGNORE_LEN_P != out_len) { *out_len = 0; } } return ret; }/*}}}*/