LPTSTR MyCharPrev( LPTSTR pszStart, LPTSTR pszStr ) // optimized version of CharPrev() /************************************************************************/ { if( !CPInfo.m_bLBRange || CPInfo.m_bLBRange[0] == NULL ) { if( pszStr > pszStart ) return( pszStr - 1 ); else return pszStart; } LPTSTR pszCurrent = pszStr; // Special case: test the first byte to the left pszStr--; if( !IsDBCSLeadByte( *pszStr )) { pszStr--; if( IsDBCSLeadByte( *pszStr )) return( pszStr ); // found a double-byte char else return( pszCurrent - 1 ); // found a single-byte char } // Step backward until a true non-lead byte is found while( IsDBCSLeadByte( *pszStr ) && ( pszStr != pszStart )) pszStr--; // pszStr points to a non-lead byte if(( pszCurrent - pszStr ) % 2 ) // all characters in-between are DBCS return( pszCurrent - 2 ); else return( pszCurrent - 1 ); // previous character is single byte }
/************************************************************************* * StrRStrIA [COMCTL32.372] * * Find the last occurrence of a substring within a string. * * PARAMS * lpszStr [I] String to search in * lpszEnd [I] End of lpszStr * lpszSearch [I] String to look for * * RETURNS * The last occurrence lpszSearch within lpszStr, or NULL if not found. */ LPSTR WINAPI StrRStrIA(LPCSTR lpszStr, LPCSTR lpszEnd, LPCSTR lpszSearch) { LPSTR lpszRet = NULL; WORD ch1, ch2; INT iLen; TRACE("(%s,%s)\n", debugstr_a(lpszStr), debugstr_a(lpszSearch)); if (!lpszStr || !lpszSearch || !*lpszSearch) return NULL; if (!lpszEnd) lpszEnd = lpszStr + lstrlenA(lpszStr); if (IsDBCSLeadByte(*lpszSearch)) ch1 = *lpszSearch << 8 | lpszSearch[1]; else ch1 = *lpszSearch; iLen = lstrlenA(lpszSearch); while (lpszStr <= lpszEnd && *lpszStr) { ch2 = IsDBCSLeadByte(*lpszStr)? *lpszStr << 8 | lpszStr[1] : *lpszStr; if (!COMCTL32_ChrCmpIA(ch1, ch2)) { if (!StrCmpNIA(lpszStr, lpszSearch, iLen)) lpszRet = (LPSTR)lpszStr; } lpszStr = CharNextA(lpszStr); } return lpszRet; }
BOOL Palette_MatchCriteria( LPTSTR lpLabel, LPTSTR lpCriteria ) /************************************************************************/ { WORD C1, C2; while( *lpCriteria ) { if( IsDBCSLeadByte(( BYTE )*lpCriteria )) C1 = MBToLowerW( lpCriteria ); else C1 = MBToLower( lpCriteria ); if( C1 == _T('*') ) // wildcard return( TRUE ); else if( !( *lpLabel )) return( FALSE ); else { if( C1 != _T('?') ) { if( IsDBCSLeadByte(( BYTE )*lpLabel )) C2 = MBToLowerW( lpLabel ); else C2 = MBToLower( lpLabel ); if( C1 != C2 ) return( FALSE ); } } lpCriteria = MyCharNext( lpCriteria ); lpLabel = MyCharNext( lpLabel ); } return( *lpLabel == _T('\0') ); }
void CUITextBox::CheckSplit( int& nCurCnt, int& nSplitCnt, int& nEnterCnt) { std::string strTmp; int pos; int len = m_Str.size(); bool bDBSC = false; #if defined(G_KOR) || defined(G_THAI) bDBSC = true; #endif pos = m_Str.find("\\n", nCurCnt); if (pos != std::string::npos && (pos - nCurCnt + 1) <= nSplitCnt) { nSplitCnt = pos - nCurCnt; nEnterCnt = 2; } // 한글인지 검사. if (bDBSC == true) { if ((nCurCnt + nSplitCnt) < len && IsDBCSLeadByte(m_Str[nCurCnt + nSplitCnt])) { bool bLead = false; for (int i = nCurCnt; i <= (nCurCnt + nSplitCnt); ++i) { if (IsDBCSLeadByte(m_Str[i])) { bLead = true; ++i; if (i > (nCurCnt + nSplitCnt)) { bLead = false; } } else { bLead = false; } } if (bLead == true) --nSplitCnt; } } if ((nCurCnt + nSplitCnt) > len) nSplitCnt = len - nCurCnt; }
/* ** char MakeCompressedName(char ARG_PTR *pszFileName); ** ** Make a file name into the corresponding compressed file name. ** ** Arguments: pszOriginalName - file name to convert to compressed file name ** ** Returns: char - Uncompressed file name extension character that was ** replaced. '\0' if no character needed to be replaced. ** ** Globals: none ** ** N.b., assumes pszFileName's buffer is long enough to hold an extra two ** characters ("._"). ** ** For DBCS filenames, we know we can have at most one DBCS character in the ** extension. So instead of just blindly replacing the last character of a ** three-byte extension with an underscore, we replace the last single-byte ** character with an underscore. */ CHAR MakeCompressedName(CHAR ARG_PTR *pszFileName) { CHAR chReplaced = '\0'; CHAR ARG_PTR *pszExt; #ifdef DBCS if ((pszExt = ExtractExtension(pszFileName)) != NULL) { if (STRLEN(pszExt) >= 3) { // Replace the last single-byte character in the extension with an // underscore. if (! IsDBCSLeadByte(*pszExt) && IsDBCSLeadByte(pszExt[1])) { // Assert: The first character in the extension is a single-byte // character and the second character in the extension is a // double-byte character. chReplaced = *pszExt; *pszExt = chEXTENSION_CHAR; } else { // Assert: The third character in the extension is a single-byte // character. The first two bytes may be two single-byte // characters or a double-byte character. chReplaced = pszExt[2]; pszExt[2] = chEXTENSION_CHAR; } } else STRCAT(pszExt, pszEXTENSION_STR); } else STRCAT(pszFileName, pszNULL_EXTENSION); #else if ((pszExt = ExtractExtension(pszFileName)) != NULL) { if (STRLEN(pszExt) >= 3) { chReplaced = pszExt[STRLEN(pszExt) - 1]; pszExt[STRLEN(pszExt) - 1] = chEXTENSION_CHAR; } else STRCAT(pszExt, pszEXTENSION_STR); } else STRCAT(pszFileName, pszNULL_EXTENSION); #endif return(chReplaced); }
void Palette_FormatEntryLabel( LPPALETTE lpPalette, BYTE Type, LPTSTR lpLabel, LPTSTR lpColorLabel ) /************************************************************************/ { STRING szString; LPTSTR lpFormat, lpString, lpCLabel; WORD wChar; BYTE lo, hi; if (lstrlen(lpPalette->szFormat) <= 0 || Type & 0x80) lstrcpy(lpColorLabel, lpLabel); else if (Type == 0 || Type == 1) { if (Type == 0) { lo = *lpLabel; hi = *(lpLabel+1); wsprintf(szString, "%u", MAKEWORD(lo, hi)); } else lstrcpy(szString, lpLabel); lpFormat = (LPTSTR)lpPalette->szFormat; lpCLabel = (LPTSTR)lpColorLabel; lpString = (LPTSTR)szString; while( *lpFormat != _T('\0' )) { if( IsDBCSLeadByte(( BYTE )*lpFormat )) wChar = *(( LPWORD )lpFormat ); else wChar = *lpFormat; if( wChar != _T('%')) { if( IsDBCSLeadByte(( BYTE )*lpFormat )) *(( LPWORD )lpCLabel ) = wChar; else *lpCLabel = wChar; lpCLabel = MyCharNext( lpCLabel ); } else { while( *lpString != _T('\0') ) *lpCLabel++ = *lpString++; } lpFormat = MyCharNext( lpFormat ); } *lpCLabel = _T('\0'); } else lpColorLabel[0] = _T('\0'); }
BOOL IsNative( LPCTSTR lpszStr ) { ASSERT( g_codePage != 0 ); LPCWSTR pwSrc = (LPCWSTR) lpszStr; if( g_codePage == 874 ) // 타이 { return (BYTE)*lpszStr >= 0xa1 && (BYTE)*lpszStr <= 0xfb; } else if( g_codePage == 949 ) // 한글 { return IsHangul( *pwSrc ); } else if( g_codePage == 932 ) // 일본 { return IsDBCSLeadByte( (BYTE)( *pwSrc ) ); } else if( g_codePage == 936 ) // 한자 : 중국 { return IsDBCSLeadByte( (BYTE)( *pwSrc ) ); } else if( g_codePage == 950 ) // 한자 : 대만 { // return IsDBCSLeadByte( *pwSrc ); if( ((BYTE)*lpszStr >= 0xCA && (BYTE)*lpszStr <= 0xFD) && ( (BYTE)*lpszStr+1 >= 0xA1 ) && ( (BYTE)*lpszStr+1 <= 0xFE) ) { return TRUE; } else if ( ( ( (BYTE)*lpszStr >= 0x41 ) && ( (BYTE)*lpszStr <= 0x5A ) ) || ( ( (BYTE)*lpszStr >= 0x61 ) && ( (BYTE)*lpszStr <= 0x7A) ) ) { return TRUE; } else if( isdigit2( (BYTE)*lpszStr ) ) return TRUE; } return FALSE; }
void SetStrNull( CString& string, int nNullLength ) { int nLength = string.GetLength(); // 0을 넣을 포지션이 실제 스트링 길이보다 길면 실제 스트링 길이로 맞출 필요가 있음 if( nNullLength > nLength ) nNullLength = nLength; int i; for( i = 0; i < nNullLength; ) { #ifdef __CLIENT if( ::GetLanguage() == LANG_THA && g_codePage == 874 ) // 타이 i++; else if(::GetLanguage() == LANG_VTN && g_codePage == 1258) i++; else #endif//__CLIENT if( IsDBCSLeadByte( string[ i ] ) ) i+=2; else i++; } // i가 nLength 보다 크다면 Word캐릭터일 것이고, 끝부분이 깨져서 오차가 생긴 것이다. if( i > nNullLength ) string = string.Left( i - 2 ); else string = string.Left( i ); }
void CFilteringTable::RemoveSpace(LPCTSTR textInput, LPTSTR textOutput, size_t size) const { TCHAR buffer[MAX_PATH] = {0}; for(PUCHAR inputPointer = PUCHAR(textInput); 0 < *inputPointer; inputPointer = _mbsinc((const PUCHAR)inputPointer)) { LPCTSTR removedSpeicalCharacter = _T("\t\n\r ~`!@#$%^&*()-_=+\\|<,>.?/"); if(_tcschr(removedSpeicalCharacter, *inputPointer)) { continue; } _tcsncat( buffer, LPCTSTR(inputPointer), IsDBCSLeadByte(*inputPointer) ? 2 : 1); } SafeStrCpy( textOutput, buffer, size); }
bool DXAPI::InitFont(){ int fontsize = 500; LOGFONT lf = {fontsize, 0, 0, 0, 0, 0, 0, 0, SHIFTJIS_CHARSET, OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FIXED_PITCH | FF_MODERN,"MS 明朝"}; HFONT hFont; if(!(hFont = CreateFontIndirect(&lf))){ return false; } HDC hdc = GetDC(NULL); HFONT oldFont = (HFONT)SelectObject(hdc, hFont); // 文字コード取得 TCHAR *c = "あ"; UINT code = 0; if(IsDBCSLeadByte(*c)) code = (BYTE)c[0]<<8 | (BYTE)c[1]; else code = c[0]; /* // フォントビットマップ取得 GetTextMetrics( hdc, &TM ); CONST MAT2 Mat = {{0,1},{0,0},{0,0},{0,1}}; DWORD size = GetGlyphOutline(hdc, code, GGO_GRAY4_BITMAP, &GM, 0, NULL, &Mat); BYTE *ptr = new BYTE[size]; GetGlyphOutline(hdc, code, GGO_GRAY4_BITMAP, &GM, size, ptr, &Mat); */ // デバイスコンテキストとフォントハンドルの開放 SelectObject(hdc, oldFont); DeleteObject(hFont); ReleaseDC(NULL, hdc); return true; }
void SetStrNull( TCHAR* lpStr, int nNullLength ) { int nLength = strlen( lpStr ); // 0을 넣을 포지션이 실제 스트링 길이보다 길면 실제 스트링 길이로 맞출 필요가 있음 if( nNullLength > nLength ) nNullLength = nLength; int i; for( i = 0; i < nNullLength; ) { #ifdef __CLIENT if( ::GetLanguage() == LANG_THA && g_codePage == 874 ) // 타이 i++; else if(::GetLanguage() == LANG_VTN && g_codePage == 1258) i++; else #endif//__CLIENT if( IsDBCSLeadByte( lpStr[ i ] ) ) i+=2; else i++; } // i가 nLength 보다 크다면 Word캐릭터일 것이고, 끝부분이 깨져서 오차가 생긴 것이다. if( i > nNullLength ) lpStr[ i - 2 ] = 0; else lpStr[ i ] = 0; }
/*========================================================================= パス合成(ANSI 版) =========================================================================*/ int MakePath(char *dest, const char *dir, const char *file, int max_len) { if (!dir) { dir = dest; } int len; if (dest == dir) { len = (int)strlen(dir); } else { len = strcpyz(dest, dir); } if (len > 0) { bool need_sep = (dest[len -1] != '\\'); if (len >= 2 && !need_sep) { // 表などで終端の場合は sep必要 BYTE *p = (BYTE *)dest; while (*p) { if (IsDBCSLeadByte(*p) && *(p+1)) { p += 2; if (!*p) { need_sep = true; } } else { p++; } } } if (need_sep) { dest[len++] = '\\'; } } return len + strncpyz(dest + len, file, max_len - len); }
//--------------------------------------------------------------------------- int TJS_mbtowc(tjs_char *pwc, const tjs_nchar *s, size_t n) { if(!s || !n) return 0; if(*s == 0) { if(pwc) *pwc = 0; return 0; } /* Borland's RTL seems to assume always MB_MAX_CHARLEN = 2. */ /* This may true while we use Win32 platforms ... */ if(IsDBCSLeadByte((BYTE)(*s))) { // multi(double) byte character if((int)n < TJS_MB_MAX_CHARLEN) return -1; if(MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, s, TJS_MB_MAX_CHARLEN, pwc, pwc ? 1:0) == 0) { if(s[1] == 0) return -1; } return TJS_MB_MAX_CHARLEN; } else { // single byte character if(MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, s, 1, pwc, pwc ? 1:0) == 0) return -1; return 1; } }
void AsciiRGB( LPTSTR pszAscii, LPRGB pRGB ) /***********************************************************************/ { LPTSTR psz, pszStr = pszAscii; WORD wChar; // replace commas with NULL terminators while( *pszStr ) { if( IsDBCSLeadByte(( BYTE )*pszStr )) wChar = *(( LPWORD )pszStr ); else wChar = *pszStr; if( wChar == _T(',') ) { psz = pszStr; pszStr = MyCharNext( pszStr ); *psz = _T('\0'); } else pszStr = MyCharNext( pszStr ); } pRGB->red = Ascii2Int( pszAscii ); pszAscii += (lstrlen( pszAscii ) + 1 ); pRGB->green = Ascii2Int( pszAscii ); pszAscii += (lstrlen( pszAscii ) + 1 ); pRGB->blue = Ascii2Int( pszAscii ); }
ULONG Ascii2ULong( LPTSTR pszAscii ) /***********************************************************************/ { WORD wChar; ULONG lValue = 0L; while( *pszAscii ) { if( IsDBCSLeadByte(( BYTE )*pszAscii )) wChar = *(( LPWORD )pszAscii ); else wChar = *pszAscii; if( wChar >= _T('0') && wChar <= _T('9') ) { lValue *= 10; lValue += ( wChar - _T('0') ); } else if( wChar >= _T(' ') ) break; pszAscii = MyCharNext( pszAscii ); } return( lValue ); }
int isUniversalCharacter(unsigned char* i) { struct _UniversalChar *p; if (IsDBCSLeadByte(*i)) { if (!g_pUC) { g_pUC = (struct _UniversalChar *)malloc(sizeof(struct _UniversalChar)); g_pUC->index = 1; g_pUC->value = *(short int *)i; g_pUC->next = 0; return 1; } for (p = g_pUC; p->next; p = p->next) { if (*(short int*)i == p->value) return p->index; } if (*(short int*)i == p->value) return p->index; p->next = (struct _UniversalChar *)malloc(sizeof(struct _UniversalChar)); p->next->index = p->index + 1; p->next->value = *(short int *)i; p->next->next = 0; return p->next->index; } return 0; }
BOOL CServerSystem::IsInvalidCharInclude( char* pStr ) { while( *pStr ) { BOOL bOk = FALSE; if( IsDBCSLeadByte( *pStr ) ) { ++pStr; } else { //영문 if( ( *pStr >= 'A' && *pStr <= 'Z' ) || ( *pStr >= 'a' && *pStr <= 'z' ) ) bOk = TRUE; //숫자 else if( *pStr >= '0' && *pStr <= '9' ) bOk = TRUE; } ++pStr; if( bOk == FALSE ) { return TRUE; } } return FALSE; }
vector<int> CglResouce::Build3DText(unsigned char *str) { vector<int> result; result.clear(); HDC hDC=wglGetCurrentDC(); //设置当前字体 SelectObject(wglGetCurrentDC(),hFont); DWORD dwChar; GLYPHMETRICSFLOAT pgmf[1]; for(size_t i=0;i<strlen((char *)str);i++) { if(IsDBCSLeadByte(str[i])) { dwChar=(DWORD)((str[i]<<8)|str[i+1]); i++; } else dwChar=str[i]; result.push_back( glGenLists(1) ); wglUseFontOutlines(hDC,dwChar,1,result.back(),0.0,0.1f,WGL_FONT_POLYGONS,pgmf); } return result; }
int CString::ReverseFind(char ch) const { LPSTR lpsz; #ifdef _WIN32 // This routine is multi-byte aware lpsz = _tcsrchr(m_pchData, (_TUCHAR)ch); #else assert(!IsDBCSLeadByte(ch)); // Visual C++ 1.52 runtime has no multi-byte aware version // of strrchr if (g_bDBCS) { LPSTR lpszLast = NULL; // Walk forward through the string remembering the last // match for (lpsz = m_pchData; *lpsz; lpsz = AnsiNext(lpsz)) { if (*lpsz == ch) lpszLast = lpsz; } lpsz = lpszLast; } else { lpsz = strrchr(m_pchData, ch); } #endif return lpsz == NULL ? -1 : (int)(lpsz - m_pchData); }
// Searching (return starting index, or -1 if not found) // look for a single character match int CString::Find(char ch) const { LPSTR lpsz; #ifdef _WIN32 lpsz = _tcschr(m_pchData, ch); #else assert(!IsDBCSLeadByte(ch)); // Visual C++ 1.52 runtime has no multi-byte aware version // of strchr if (g_bDBCS) { if (ch == '\0') lpsz = m_pchData + m_nDataLength; else { // Use the MBCS routine to step through the characters for (lpsz = m_pchData; *lpsz; lpsz = AnsiNext(lpsz)) { if (*lpsz == ch) break; } if (*lpsz == '\0') { lpsz = NULL; // No match. } } } else { lpsz = strchr(m_pchData, ch); } #endif return lpsz == NULL ? -1 : (int)(lpsz - m_pchData); }
void AsciiToInt4( LPTSTR pszAscii, LPINT a, LPINT b, LPINT c, LPINT d ) /***********************************************************************/ { LPTSTR psz, pszStr = pszAscii; WORD wChar; while( *pszStr ) { if( IsDBCSLeadByte(( BYTE )*pszStr )) wChar = *(( LPWORD )pszStr ); else wChar = *pszStr; if( wChar == _T(',') ) { psz = pszStr; pszStr = MyCharNext( pszStr ); *psz = _T('\0'); } else pszStr = MyCharNext( pszStr ); } psz = pszStr; *a = Ascii2Int( psz ); psz += (lstrlen( psz ) + 1 ); *b = Ascii2Int( psz ); psz += (lstrlen( psz ) + 1 ); *c = Ascii2Int( psz ); psz += (lstrlen( psz ) + 1 ); *d = Ascii2Int( psz ); }
void Window::drawString(string str) { int len = 0; wchar_t* wstring; HDC hDC = wglGetCurrentDC(); for (int i = 0; str[i] != '\0'; ++i) { if (IsDBCSLeadByte(str[i])) ++i; ++len; } GLuint list = glGenLists(1); // 将混合字符转化为宽字符 wstring = (wchar_t*)malloc((len + 1) * sizeof(wchar_t)); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, wstring, len); wstring[len] = L'\0'; // 逐个输出字符 for (int i = 0; i < len; ++i) { wglUseFontBitmapsW(hDC, wstring[i], 1, list); glCallList(list); } // 回收所有临时资源 free(wstring); glDeleteLists(list, 1); }
void CFontDisplay::drawCNString(const char* str) { int len, i; wchar_t* wstring; HDC hDC = wglGetCurrentDC(); GLuint list = glGenLists(1); // 计算字符的个数 // 如果是双字节字符的(比如中文字符),两个字节才算一个字符 // 否则一个字节算一个字符 len = 0; for(i=0; str[i]!='\0'; ++i) { if( IsDBCSLeadByte(str[i]) ) ++i; ++len; } // 将混合字符转化为宽字符 wstring = (wchar_t*)malloc((len+1) * sizeof(wchar_t)); MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstring, len); wstring[len] = L'\0'; // 逐个输出字符 for(i=0; i<len; ++i) { wglUseFontBitmapsW(hDC, wstring[i], 1, list); glCallList(list); } // 回收所有临时资源 free(wstring); glDeleteLists(list, 1); }
void CGLFont::Printfc3d(CString strText,HFONT hFont,float z) { HDC hdc = wglGetCurrentDC(); //设备场景 HFONT hOldFont=(HFONT)::SelectObject(hdc,hFont);//将字体选入场景 UCHAR * pChar=(UCHAR*)strText.GetBuffer(strText.GetLength());//定义字符串长度 int nListNum; //显示列表 DWORD dwChar; //字符指针 GLYPHMETRICSFLOAT pgmf[1]; //轮廓字体字符集的信息 glPushMatrix(); //压入堆栈 for(int i = 0; i < strText.GetLength(); i++) { if(IsDBCSLeadByte((BYTE)pChar[i])) //是否双字节(汉字) { dwChar=(DWORD)((pChar[i]<<8)|pChar[i+1]); //取当前字符,双字节转换 i++; } else dwChar = pChar[i]; //取当前字符 nListNum = glGenLists(1); //创建列表 wglUseFontOutlines( hdc, //拥有字体的HDC dwChar, //转化为显示列表的第一个字符 1, //转化为显示列表的字符数 nListNum, //显示列表的开始 0.0f, z, //Z轴负方向的厚度 WGL_FONT_POLYGONS, //绘制字体方式 pgmf //指向存放信息的数组,为count个 ); glCallList(nListNum); //绘制显示列表 glDeleteLists(nListNum, 1); //删除列表 } glPopMatrix(); //弹出堆栈 strText.ReleaseBuffer(); //清除字符串 ::SelectObject(hdc,hOldFont); //恢复字体 }
static long getWin32SelPos(AwtTextComponent *c, long orgPos) { long mblen; long pos = 0; long cur = 0; TCHAR *mbbuf; if ((mblen = c->GetTextLength()) == 0) return 0; mbbuf = new TCHAR[mblen + 1]; c->GetText(mbbuf, mblen + 1); while (cur < orgPos && pos < mblen) { #ifndef UNICODE if (IsDBCSLeadByte(mbbuf[pos])) { pos++; } else if (mbbuf[pos] == '\r' && mbbuf[pos + 1] == '\n') { pos++; } #else if (mbbuf[pos] == TEXT('\r') && mbbuf[pos + 1] == TEXT('\n')) { pos++; } #endif pos++; cur++; } delete[] mbbuf; return pos; }
void AsciiToInt2( LPTSTR pszAscii, LPINT a, LPINT b ) /***********************************************************************/ { LPTSTR psz, pszStr = pszAscii; WORD wChar; // replace commas with NULL terminators while( *pszStr ) { if( IsDBCSLeadByte(( BYTE )*pszStr )) wChar = *(( LPWORD )pszStr ); else wChar = *pszStr; if( wChar == _T(',') ) { psz = pszStr; pszStr = MyCharNext( pszStr ); *psz = _T('\0'); } else pszStr = MyCharNext( pszStr ); } pszStr = pszAscii; *a = Ascii2Int( pszStr ); pszStr += ( lstrlen( pszStr ) + 1 ); *b = Ascii2Int( pszStr ); }
void TrimViewString(CmyString &strDst, LPCSTR pszSrc) { int i, nLen; BYTE byTmp; char szTmp[3]; strDst.Empty (); if (pszSrc == NULL) { return; } nLen = strlen (pszSrc); if (nLen <= 0) { return; } ZeroMemory (szTmp, sizeof (szTmp)); for (i = 0; i < nLen; i ++) { byTmp = (BYTE)pszSrc[i]; if (IsDBCSLeadByte (byTmp)) { szTmp[0] = byTmp; szTmp[1] = pszSrc[i + 1]; strDst += szTmp; i ++; continue; } if ((byTmp < 0x20) || ((byTmp >= 0x7F) && !((byTmp >= 0xA1) && (byTmp <= 0xDF)))) { continue; } szTmp[0] = byTmp; szTmp[1] = 0; strDst += szTmp; } }
// ----------------------------------------------------------------------- // // String helper function to remove crt dependency // // ----------------------------------------------------------------------- LPSTR mystrchr( __in LPSTR cs, char c ) { while (*cs != 0) { if (IsDBCSLeadByte(*cs)) { cs++; if (*cs == 0) { return NULL; } } else if (*cs == c) return cs; cs++; } // fail to find c in cs return NULL; }
//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::NativeToUnix(nsSimpleCharString& ioPath) // This just does string manipulation. It doesn't check reality, or canonify, or // anything. The unix path is longer, so we can't do it in place. //---------------------------------------------------------------------------------------- { if (ioPath.IsEmpty()) return; // Convert the drive-letter separator, if present nsSimpleCharString temp("/"); char* cp = (char*)ioPath + 1; if (strstr(cp, ":\\") == cp) *cp = '|'; // absolute path else if (cp[0] == '\\') // unc path cp--; else temp[0] = '\0'; // relative path // Convert '\' to '/' for (; *cp; cp++) { if(IsDBCSLeadByte(*cp) && *(cp+1) != nsnull) { cp++; continue; } if (*cp == '\\') *cp = '/'; } // Add the slash in front. temp += ioPath; ioPath = temp; }
extern "C" DIR *opendir(const char *dir) { DIR *dp; char *filespec; long handle; int index; filespec = (char *)malloc(strlen(dir) + 2 + 1); strcpy(filespec, dir); index = strlen(filespec) - 1; if (index >= 0 && (filespec[index] == '/' || (filespec[index] == '\\' && !IsDBCSLeadByte(filespec[index-1])))) filespec[index] = '\0'; strcat(filespec, "/*"); dp = (DIR *) malloc(sizeof(DIR)); dp->offset = 0; dp->finished = 0; if ((handle = _findfirst(filespec, &(dp->fileinfo))) < 0) { if (errno == ENOENT) { dp->finished = 1; } else { free(dp); free(filespec); return NULL; } } dp->dir = strdup(dir); dp->handle = handle; free(filespec); return dp; }