Ejemplo n.º 1
0
BOOL WINAPI IsCharAlphaNumericW(
    WCHAR wChar)
{
    WORD ctype1info;

    if (!GetStringTypeW(CT_CTYPE1, &wChar, 1, &ctype1info)) {
        //
        // GetStringTypeW returned an error!  IsCharAlphaNumericW has no
        // provision for returning an error...  The best we can do is to
        // return FALSE
        //
        UserAssert(FALSE);
        return FALSE;
    }
    //
    // LATER 20 Feb 92 GregoryW
    //    We may need to check ctype 3 info if we want to check for
    //    digits other than ASCII '0'-'9' (such as Lao digits or
    //    Tibetan digits, etc.).
    //
#ifdef FE_SB // IsCharAlphaNumericW()
    if (ctype1info & C1_ALPHA) {
        WORD ctype3info = 0;
        /*
         * We don't want to return TRUE for halfwidth katakana.
         * Katakana is linguistic character (C1_ALPHA), but it is not
         * alphabet character.
         */
        if (!GetStringTypeW(CT_CTYPE3, &wChar, 1, &ctype3info)) {
            UserAssert(FALSE);
            /*
             * Assume, it is alphabet character, because it has
             * C1_ALPHA attribute.
             */
            return TRUE;
        }

        if (ctype3info & (C3_KATAKANA|C3_HIRAGANA)) {
            /*
             * This is 'Katakana'.
             */
            return FALSE;
        } else {
            return TRUE;
        }
    } else if (ctype1info & C1_DIGIT) {
        return TRUE;
    } else {
        return FALSE;
    }
#else
    if ((ctype1info & C1_ALPHA) || (ctype1info & C1_DIGIT)) {
        return TRUE;
    } else {
        return FALSE;
    }
#endif // FE_SB
}
Ejemplo n.º 2
0
void RTL_DetectAndSet(ClcContact *contact, MCONTACT hContact)
{
	WORD infoTypeC2[12];
	int i;
	TCHAR *szText = NULL;
	DWORD iLen;
	TExtraCache *p;

	ZeroMemory(infoTypeC2, sizeof(WORD) * 12);

	if (contact == NULL) {
		szText = pcli->pfnGetContactDisplayName(hContact, 0);
		p = cfg::getCache(hContact, NULL);
	}
	else {
		szText = contact->szText;
		p = contact->pExtra;
	}
	if (p) {
		iLen = min(lstrlenW(szText), 10);
		GetStringTypeW(CT_CTYPE2, szText, iLen, infoTypeC2);
		p->dwCFlags &= ~ECF_RTLNICK;
		for (i = 0; i < 10; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
				p->dwCFlags |= ECF_RTLNICK;
				return;
			}
		}
	}
}
Ejemplo n.º 3
0
LPWSTR WINAPI CharNextW(
    LPCWSTR lpwCurrentChar)
{
    WORD ctype3info;

    if (*lpwCurrentChar) {
        //
        // Examine each code element.  Skip all combining elements.
        //
        while (*(++lpwCurrentChar)) {
            if (!GetStringTypeW(
                    CT_CTYPE3,
                    lpwCurrentChar,
                    1,
                    &ctype3info)) {
                /*
                 * GetStringTypeW failed!  The caller is not expecting failure,
                 * CharNextW does not have a failure indicator, so just return
                 * a pointer to the character we couldn't analyze.
                 */
                RIPMSG2(RIP_WARNING, "CharNextW failed, L'\\x%.4x' at %#p",
                        *lpwCurrentChar, lpwCurrentChar);
                break;
            }
            if (!((ctype3info & C3_NONSPACING) && (!(ctype3info & C3_ALPHA)))) {
                break;
            }
        }
    }

    return (LPWSTR)lpwCurrentChar;
}
Ejemplo n.º 4
0
BOOL WINAPI IsCharUpperW(
    WCHAR wChar)
{
    WORD ctype1info;

    if (GetStringTypeW(CT_CTYPE1, &wChar, 1, &ctype1info)) {
        if (ctype1info & C1_UPPER) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    /*
     * GetStringTypeW failed!  The caller is not expecting
     * failure, IsCharLowerW does not have a failure indicator, so we
     * determine the case as best we can.
     */
    RIPMSG1(RIP_WARNING, "IsCharUpper(L'\\x%.4lx') failed", wChar);

    if (IS_UNICODE_BLK1(wChar)) {
        return IsCharUpperA((CHAR)wChar);
    } else {
        return FALSE;
    }
}
Ejemplo n.º 5
0
void RTL_DetectAndSet(struct ClcContact *contact, MCONTACT hContact)
{
    WORD infoTypeC2[12];
    int i, index;
    wchar_t *szText = NULL;
    DWORD iLen;

    ZeroMemory(infoTypeC2, sizeof(WORD) * 12);

    if(contact == NULL) {
        szText = pcli->pfnGetContactDisplayName(hContact, 0);
        index = cfg::getCache(hContact, NULL);
    }
    else {
        szText = contact->szText;
        index = contact->extraCacheEntry;
    }
    if(index >= 0 && index < cfg::nextCacheEntry) {
        iLen = min(lstrlenW(szText), 10);
        GetStringTypeW(CT_CTYPE2, szText, iLen, infoTypeC2);
        cfg::eCache[index].dwCFlags &= ~ECF_RTLNICK;
        for(i = 0; i < 10; i++) {
            if(infoTypeC2[i] == C2_RIGHTTOLEFT) {
                cfg::eCache[index].dwCFlags |= ECF_RTLNICK;
                return;
            }
        }
    }
}
Ejemplo n.º 6
0
BOOL WINAPI IsCharAlphaW(
    WCHAR wChar)
{
    WORD ctype1info;

    if (!GetStringTypeW(CT_CTYPE1, &wChar, 1, &ctype1info)) {
        //
        // GetStringTypeW returned an error!  IsCharAlphaW has no
        // provision for returning an error...  The best we can do
        // is to return FALSE
        //
        UserAssert(FALSE);
        return FALSE;
    }
    if (ctype1info & C1_ALPHA) {
#ifdef FE_SB // IsCharAlphaA()
        WORD ctype3info = 0;
        /*
         * We don't want to return TRUE for halfwidth katakana.
         * Katakana is linguistic character (C1_ALPHA), but it is not
         * alphabet character.
         */
        if (!GetStringTypeW(CT_CTYPE3, &wChar, 1, &ctype3info)) {
            UserAssert(FALSE);
            /*
             * Assume, it is alphabet character, because it has
             * C1_ALPHA attribute.
             */
            return TRUE;
        }

        if (ctype3info & (C3_KATAKANA|C3_HIRAGANA)) {
            /*
             * This is 'Katakana'.
             */
            return FALSE;
        } else {
            return TRUE;
        }
#else
        return TRUE;
#endif // FE_SB
    } else {
        return FALSE;
    }
}
Ejemplo n.º 7
0
_CRTIMP2_PURE const wchar_t * __CLRCALL_PURE_OR_CDECL _Getwctypes(
	const wchar_t *_First, const wchar_t *_Last,
		short *_Dest, const _Ctypevec *_Ctype)
	{	/* get mask sequence for elements in [_First, _Last) */
	GetStringTypeW(CT_CTYPE1, _First, (int)(_Last - _First),
		(LPWORD)_Dest);
	return (_Last);
	}
Ejemplo n.º 8
0
/*********************************************************************
 *              __crtGetStringTypeW(MSVCRT.@)
 *
 * This function was accepting different number of arguments in older
 * versions of msvcrt.
 */
BOOL CDECL __crtGetStringTypeW(DWORD unk, DWORD type,
        wchar_t *buffer, int len, WORD *out)
{
    FIXME("(unk %x, type %x, wstr %p(%d), %p) partial stub\n",
            unk, type, buffer, len, out);

    return GetStringTypeW(type, buffer, len, out);
}
Ejemplo n.º 9
0
_CRTIMP2_PURE short __CLRCALL_PURE_OR_CDECL _Getwctype(wchar_t _Ch,
	const _Ctypevec *_Ctype)
	{	/* return character classification flags for _Ch */
	_CRT_UNUSED(_Ctype);
	short _Mask;
	return ((short)(GetStringTypeW(CT_CTYPE1, &_Ch, 1,
		(LPWORD)&_Mask) == 0
		? 0 : _Mask));
	}
Ejemplo n.º 10
0
static void test_crtGetStringTypeW(void)
{
    static const wchar_t str0[] = { '0', '\0' };
    static const wchar_t strA[] = { 'A', '\0' };
    static const wchar_t str_space[] = { ' ', '\0' };
    static const wchar_t str_null[] = { '\0', '\0' };
    static const wchar_t str_rand[] = { 1234, '\0' };

    const wchar_t *str[] = { str0, strA, str_space, str_null, str_rand };

    WORD out_crt, out;
    BOOL ret_crt, ret;
    int i;

    if(!p__crtGetStringTypeW) {
        win_skip("Skipping __crtGetStringTypeW tests\n");
        return;
    }

    if(!pmemcpy_s) {
        win_skip("Too old version of msvcrt.dll\n");
        return;
    }

    for(i=0; i<ARRAY_SIZE(str); i++) {
        ret_crt = p__crtGetStringTypeW(0, CT_CTYPE1, str[i], 1, &out_crt);
        ret = GetStringTypeW(CT_CTYPE1, str[i], 1, &out);
        ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
        ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);

        ret_crt = p__crtGetStringTypeW(0, CT_CTYPE2, str[i], 1, &out_crt);
        ret = GetStringTypeW(CT_CTYPE2, str[i], 1, &out);
        ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
        ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);

        ret_crt = p__crtGetStringTypeW(0, CT_CTYPE3, str[i], 1, &out_crt);
        ret = GetStringTypeW(CT_CTYPE3, str[i], 1, &out);
        ok(ret == ret_crt, "%d) ret_crt = %d\n", i, (int)ret_crt);
        ok(out == out_crt, "%d) out_crt = %x, expected %x\n", i, (int)out_crt, (int)out);
    }

    ret = p__crtGetStringTypeW(0, 3, str[0], 1, &out);
    ok(!ret, "ret == TRUE\n");
}
Ejemplo n.º 11
0
  _Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype* ltype, wint_t c,
                                     _Locale_mask_t which_bits) {
    wchar_t buf[2];
    WORD out[2];
    buf[0] = c; buf[1] = 0;
    GetStringTypeW(CT_CTYPE1, buf, -1, out);

    return (_Locale_mask_t)out[0] & which_bits;
    //	ltype;
  }
Ejemplo n.º 12
0
Archivo: text.c Proyecto: RPG-7/reactos
static WORD
GetC1Type(WCHAR Ch)
{
    WORD CharType;

    if (! GetStringTypeW(CT_CTYPE1, &Ch, 1, &CharType))
    {
        return 0;
    }

    return CharType;
}
Ejemplo n.º 13
0
/**
 * @brief Get canonical application name (all non-alphanumeric characters are stripped).
 * @param pszAppName - buffer for resulting application name.
 * @param nBufferSize - size of file name buffer.
 * @param bAllowSpaces - true if spaces are allowed.
 * @return length of the name.
 */
size_t GetCanonicalAppName(PTSTR pszAppName, size_t nBufferSize, BOOL bAllowSpaces)
{
	if (nBufferSize == 0)
		return 0;
	if (*g_szAppName != _T('\0'))
	{
		--nBufferSize;
		size_t nStrLength = _tcslen(g_szAppName);
		if (nStrLength > nBufferSize)
			nStrLength = nBufferSize;
		size_t nSrcPos = 0, nDstPos = 0;
		WORD wCharMask = C1_ALPHA | C1_DIGIT;
		if (bAllowSpaces)
			wCharMask |= C1_SPACE;
		while (nSrcPos < nStrLength)
		{
			WORD arrCharType[2];
#ifdef _UNICODE
			size_t nCharSize = GetUnicodeCharSize((const BYTE*)(g_szAppName + nSrcPos)) / sizeof(WCHAR);
			GetStringTypeW(CT_CTYPE1, g_szAppName + nSrcPos, (int)nCharSize, arrCharType);
#else
			size_t nCharSize = IsDBCSLeadByte(g_szAppName[nSrcPos]) ? 2 : 1;
			GetStringTypeA(LOCALE_USER_DEFAULT, CT_CTYPE1, g_szAppName + nSrcPos, (int)nCharSize, arrCharType);
#endif
			if (*arrCharType & wCharMask)
			{
				pszAppName[nDstPos++] = g_szAppName[nSrcPos++];
				if (nCharSize > 1)
					pszAppName[nDstPos++] = g_szAppName[nSrcPos++];
			}
			else
			{
				/*if (*arrCharType & C1_SPACE)
					pszAppName[nDstPos++] = _T('_');*/
				nSrcPos += (DWORD)nCharSize;
			}
		}
		pszAppName[nDstPos] = _T('\0');
		return nDstPos;
	}
	else
	{
		TCHAR szAppFileName[MAX_PATH];
		if (! GetModuleFileName(NULL, szAppFileName, countof(szAppFileName)))
			return FALSE;
		PTSTR pszFileName = PathFindFileName(szAppFileName);
		PathRemoveExtension(pszFileName);
		_tcscpy_s(pszAppName, nBufferSize, pszFileName);
		return _tcslen(pszAppName);
	}
}
Ejemplo n.º 14
0
void RTL_DetectGroupName(ClcContact *group)
{
	WORD infoTypeC2[12];

	group->isRtl = 0;

	if (group->szText) {
		int iLen = min((int)mir_wstrlen(group->szText), 10);
		GetStringTypeW(CT_CTYPE2, group->szText, iLen, infoTypeC2);
		for (int i = 0; i < 10; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
				group->isRtl = 1;
				return;
			}
		}
	}
}
Ejemplo n.º 15
0
int SendQueue::RTL_Detect(const WCHAR *pszwText)
{
	int i, n = 0;
	size_t iLen = mir_wstrlen(pszwText);

	WORD *infoTypeC2 = (WORD*)mir_calloc(sizeof(WORD) * (iLen + 2));
	if (infoTypeC2 == NULL)
		return 0;

	GetStringTypeW(CT_CTYPE2, pszwText, (int)iLen, infoTypeC2);

	for (i = 0; i < iLen; i++)
		if (infoTypeC2[i] == C2_RIGHTTOLEFT)
			n++;

	mir_free(infoTypeC2);
	return(n >= 2 ? 1 : 0);
}
Ejemplo n.º 16
0
int SendQueue::RTL_Detect(const WCHAR *pszwText)
{
	WORD	*infoTypeC2;
	int		i, n = 0;
	int		iLen = lstrlenW(pszwText);

	infoTypeC2 = (WORD *)mir_alloc(sizeof(WORD) * (iLen + 2));

	if (infoTypeC2) {
		ZeroMemory(infoTypeC2, sizeof(WORD) * (iLen + 2));

		GetStringTypeW(CT_CTYPE2, pszwText, iLen, infoTypeC2);

		for (i = 0; i < iLen; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT)
				n++;
		}
		mir_free(infoTypeC2);
		return(n >= 2 ? 1 : 0);
	}
	return 0;
}
Ejemplo n.º 17
0
BYTE GetCachedStatusMsg(TExtraCache *p, char *szProto)
{
	if (p == NULL)
		return 0;

	p->bStatusMsgValid = STATUSMSG_NOTFOUND;
	MCONTACT hContact = p->hContact;

	DBVARIANT dbv = {0};
	INT_PTR result = cfg::getTString(hContact, "CList", "StatusMsg", &dbv);
	if ( !result && lstrlen(dbv.ptszVal) > 0)
		p->bStatusMsgValid = STATUSMSG_CLIST;
	else {
		if ( !szProto)
			szProto = GetContactProto(hContact);
		if (szProto) {
			if ( !result )
				db_free( &dbv );
			if ( !( result = cfg::getTString(hContact, szProto, "YMsg", &dbv)) && lstrlen(dbv.ptszVal) > 0)
				p->bStatusMsgValid = STATUSMSG_YIM;
			else if ( !(result = cfg::getTString(hContact, szProto, "StatusDescr", &dbv)) && lstrlen(dbv.ptszVal) > 0)
				p->bStatusMsgValid = STATUSMSG_GG;
			else if ( !(result = cfg::getTString(hContact, szProto, "XStatusMsg", &dbv)) && lstrlen(dbv.ptszVal) > 0)
				p->bStatusMsgValid = STATUSMSG_XSTATUS;
		}
	}

	if (p->bStatusMsgValid == STATUSMSG_NOTFOUND) { // no status msg, consider xstatus name (if available)
		if ( !result )
			db_free( &dbv );
		result = cfg::getTString(hContact, szProto, "XStatusName", &dbv);
		if ( !result && lstrlen(dbv.ptszVal) > 1) {
			int iLen = lstrlen(dbv.ptszVal);
			p->bStatusMsgValid = STATUSMSG_XSTATUSNAME;
			p->statusMsg = (TCHAR *)realloc(p->statusMsg, (iLen + 2) * sizeof(TCHAR));
			_tcsncpy(p->statusMsg, dbv.ptszVal, iLen + 1);
		}
		else {
			int xStatus;
			WPARAM xStatus2;
			TCHAR xStatusName[128];

			CUSTOM_STATUS cst = { sizeof(cst) };
			cst.flags = CSSF_MASK_STATUS;
			cst.status = &xStatus;
			if (ProtoServiceExists(szProto, PS_GETCUSTOMSTATUSEX) && !ProtoCallService(szProto, PS_GETCUSTOMSTATUSEX, hContact, (LPARAM)&cst) && xStatus > 0) {
				cst.flags = CSSF_MASK_NAME | CSSF_DEFAULT_NAME | CSSF_TCHAR;
 				cst.wParam = &xStatus2;
				cst.ptszName = xStatusName;
				if ( !CallProtoService(szProto, PS_GETCUSTOMSTATUSEX, hContact, (LPARAM)&cst)) {
					TCHAR *szwXstatusName = TranslateTS(xStatusName);
					p->statusMsg = (TCHAR *)realloc(p->statusMsg, (lstrlen(szwXstatusName) + 2) * sizeof(TCHAR));
					_tcsncpy(p->statusMsg, szwXstatusName, lstrlen(szwXstatusName) + 1);
					p->bStatusMsgValid = STATUSMSG_XSTATUSNAME;
				}
			}
		}
	}

	if (p->bStatusMsgValid > STATUSMSG_XSTATUSNAME) {
		int j = 0;
		p->statusMsg = (TCHAR *)realloc(p->statusMsg, (lstrlen(dbv.ptszVal) + 2) * sizeof(TCHAR));
		for (int i = 0; dbv.ptszVal[i]; i++) {
			if (dbv.ptszVal[i] == (TCHAR)0x0d)
				continue;
			p->statusMsg[j] = dbv.ptszVal[i] == (wchar_t)0x0a ? (wchar_t)' ' : dbv.ptszVal[i];
			j++;
		}
		p->statusMsg[j] = 0;
	}
	if ( !result )
		db_free( &dbv );

	if (p->bStatusMsgValid != STATUSMSG_NOTFOUND) {
		WORD infoTypeC2[12];
		ZeroMemory(infoTypeC2, sizeof(WORD) * 12);
		int iLen = min(lstrlenW(p->statusMsg), 10);
		GetStringTypeW(CT_CTYPE2, p->statusMsg, iLen, infoTypeC2);
		p->dwCFlags &= ~ECF_RTLSTATUSMSG;
		for (int i = 0; i < 10; i++) {
			if (infoTypeC2[i] == C2_RIGHTTOLEFT) {
				p->dwCFlags |= ECF_RTLSTATUSMSG;
				break;
			}
		}
	}

	if (p->hTimeZone == NULL)
		TZ_LoadTimeZone(hContact, p, szProto);
	return p->bStatusMsgValid;
}
NS_IMETHODIMP 
sbStringTransformImpl::NormalizeString(const nsAString & aCharset, 
                                       PRUint32 aTransformFlags, 
                                       const nsAString & aInput, 
                                       nsAString & _retval)
{
  nsString finalStr;
  nsString inStr(aInput);

  if(inStr.IsEmpty()) {
    _retval.Truncate();
    return NS_OK;
  }

  nsTArray<WORD> excludeChars[NTYPES];
  nsTArray<WORD> includeChars[NTYPES];
  DWORD dwFlags = MakeFlags(aTransformFlags, 
                            excludeChars,
                            includeChars);

  if(aTransformFlags & sbIStringTransform::TRANSFORM_LOWERCASE ||
     aTransformFlags & sbIStringTransform::TRANSFORM_UPPERCASE) {

    WCHAR *wszJunk = {0};
    int requiredBufferSize = ::LCMapStringW(LOCALE_USER_DEFAULT,
                                            dwFlags,
                                            inStr.BeginReading(),
                                            inStr.Length(),
                                            wszJunk,
                                            0);

    nsString bufferStr;
    int convertedChars = 
      ::LCMapStringW(LOCALE_USER_DEFAULT, 
                     dwFlags, 
                     inStr.BeginReading(), 
                     inStr.Length(), 
                     bufferStr.BeginWriting(requiredBufferSize),
                     requiredBufferSize);

    NS_ENSURE_TRUE(convertedChars == requiredBufferSize, 
                   NS_ERROR_CANNOT_CONVERT_DATA);

    finalStr = bufferStr;
    inStr = bufferStr;
  }

  if(aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_NONSPACE ||
     aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_SYMBOLS ||
     aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM ||
     aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_NONALPHANUM_IGNORE_SPACE) {
    PRBool leadingOnly = aTransformFlags & 
                         sbIStringTransform::TRANSFORM_IGNORE_LEADING;
    PRBool bypassTest = PR_FALSE;
    LPWSTR wszJunk = {0};
    int requiredBufferSize = ::FoldStringW(MAP_COMPOSITE, 
                                           inStr.BeginReading(), 
                                           inStr.Length(), 
                                           wszJunk, 
                                           0);

    nsString bufferStr;
    int convertedChars = 
      ::FoldStringW(MAP_COMPOSITE, 
                    inStr.BeginReading(),
                    inStr.Length(),
                    bufferStr.BeginWriting(requiredBufferSize),
                    requiredBufferSize);

    NS_ENSURE_TRUE(convertedChars == requiredBufferSize,
                   NS_ERROR_CANNOT_CONVERT_DATA);

    LPWORD ct1 = new WORD[requiredBufferSize];
    BOOL success = GetStringTypeW(CT_CTYPE1,
                                  (LPWSTR) bufferStr.BeginReading(), 
                                  bufferStr.Length(), 
                                  &ct1[0]);

    if(!success) {
      delete [] ct1;
      _retval.Truncate();
      return NS_ERROR_CANNOT_CONVERT_DATA;
    }

    LPWORD ct2 = new WORD[requiredBufferSize];
    success = GetStringTypeW(CT_CTYPE2,
                             (LPWSTR) bufferStr.BeginReading(), 
                             bufferStr.Length(), 
                             &ct2[0]);

    if(!success) {
     delete [] ct1;
     delete [] ct2;
     _retval.Truncate();
     return NS_ERROR_CANNOT_CONVERT_DATA;
    }

    LPWORD ct3 = new WORD[requiredBufferSize];
    success = GetStringTypeW(CT_CTYPE3,
                             (LPWSTR) bufferStr.BeginReading(), 
                             bufferStr.Length(), 
                             &ct3[0]);

    if(!success) {
     delete [] ct1;
     delete [] ct2;
     delete [] ct3;
     _retval.Truncate();
     return NS_ERROR_CANNOT_CONVERT_DATA;
    }

    LPWORD charTypes[NTYPES] = {ct1, ct2, ct3};

    for(int current = 0; current < requiredBufferSize; ++current) {
      PRBool validChar = PR_TRUE;
      PRInt32 skipChars = 0;

      if (!bypassTest) {
        if (aTransformFlags & sbIStringTransform::TRANSFORM_IGNORE_KEEPNUMBERSYMBOLS) {
          PRInt32 numberLength;
          SB_ExtractLeadingNumber(bufferStr.BeginReading() + current, NULL, NULL, &numberLength);
          if (numberLength > 0) {
            finalStr.Append(bufferStr.BeginReading() + current, numberLength);
            current += numberLength-1;
            if (leadingOnly) {
              bypassTest = PR_TRUE;
            }
            continue;
          }
        }
        
        // first check if the char is excluded by any of its type flags
        for (int type = FIRSTTYPE; type <= LASTTYPE && validChar; type++) {
          PRUint32 excludeCharsLength = excludeChars[type].Length();
          for(PRUint32 invalid = 0; invalid < excludeCharsLength; ++invalid) {
            if(excludeChars[type][invalid] & charTypes[type][current]) {
              validChar = PR_FALSE;
              break;
            }
          }
        }
        // next, check if the char is in the included chars arrays. if all
        // arrays are empty, allow all chars instead of none
        PRBool found = PR_FALSE;
        PRBool testedAnything = PR_FALSE;
        for (int type = FIRSTTYPE; 
             type <= LASTTYPE && validChar && !found; 
             type++) {
          PRUint32 includeCharsLength = includeChars[type].Length();
          for(PRUint32 valid = 0; valid < includeCharsLength; ++valid) {
            testedAnything = PR_TRUE;
            if (includeChars[type][valid] & charTypes[type][current]) {
              found = PR_TRUE;
              break;
            }
          }
        }
        if (testedAnything && 
            !found) {
          validChar = PR_FALSE;    
        }
      }
            
      if(validChar) {
        if (leadingOnly) {
          bypassTest = PR_TRUE;
        }
        finalStr.Append(bufferStr.CharAt(current));
      }
      current += skipChars;
    }

    delete [] ct1;
    delete [] ct2;
    delete [] ct3;
  }

  _retval = finalStr;

  return NS_OK;
}
Ejemplo n.º 19
0
/* and the C2_* type in the high 4 bits */
static __inline unsigned short get_char_typeW( WCHAR ch )
{
    WORD CharType;
    GetStringTypeW(CT_CTYPE1, &ch, 1, &CharType);
    return CharType;
}
Ejemplo n.º 20
0
void CCrystalParser::WrapLine( int nLineIndex, int nMaxLineWidth, int *anBreaks, int &nBreaks )
{
	// The parser must be attached to a view!
	ASSERT( m_pTextView );

	int			nLineLength = m_pTextView->GetLineLength( nLineIndex );
	int			nTabWidth = m_pTextView->GetTabSize();
	int			nLineCharCount = 0;
	int			nCharCount = 0;
	LPCTSTR	szLine = m_pTextView->GetLineChars( nLineIndex );
	int			nLastBreakPos = 0;
	int			nLastCharBreakPos = 0;
	BOOL		bBreakable = FALSE;

	for( int i = 0; i < nLineLength; i += EnsureCharNext(szLine + i) - (szLine + i) )
	{
		// remember position of whitespace for wrap
		if( bBreakable )
		{
			nLastBreakPos = i;
			nLastCharBreakPos = nCharCount;
			bBreakable = FALSE;
		}

		// increment char counter (evtl. expand tab)
		if( szLine[i] == _T('\t') )
		{
			nLineCharCount+= (nTabWidth - nCharCount % nTabWidth);
			nCharCount+= (nTabWidth - nCharCount % nTabWidth);
		}
		else
		{
			if( IsDBCSLeadByte((BYTE)szLine[i]) )
			{
				nLineCharCount += 2;
				nCharCount += 2;
			}
			else
			{
				nLineCharCount += m_pTextView->GetCharWidthFromChar(szLine[i]) / m_pTextView->GetCharWidth();
				nCharCount += m_pTextView->GetCharWidthFromChar(szLine[i]) / m_pTextView->GetCharWidth();
			}
		}

		// remember whitespace
		WORD wCharType;
		GetStringTypeW(CT_CTYPE3, &szLine[i], 1, &wCharType);
		if( szLine[i] == _T('\t') || szLine[i] == _T(' ') || (wCharType & (C3_IDEOGRAPH | C3_HIRAGANA | C3_KATAKANA)))
			bBreakable = TRUE;

		// wrap line
		if( nLineCharCount >= nMaxLineWidth )
		{
			// if no wrap position found, but line is to wide, 
			// wrap at current position
			if( nLastBreakPos == 0 )
			{
				nLastBreakPos = i;
				nLastCharBreakPos = nCharCount;
			}
			if( anBreaks )
				anBreaks[nBreaks++] = nLastBreakPos;
			else
				nBreaks++;

			nLineCharCount = nCharCount - nLastCharBreakPos;
			nLastBreakPos = 0;
		}
	}
}
Ejemplo n.º 21
0
static BOOL __cdecl __crtGetStringTypeA_stat(
        _locale_t plocinfo,
        DWORD    dwInfoType,
        LPCSTR   lpSrcStr,
        int      cchSrc,
        LPWORD   lpCharType,
        int      code_page,
        int      lcid,
        BOOL     bError
        )
{
    static int f_use = 0;

    /*
     * Look for unstubbed 'preferred' flavor. Otherwise use available
     * flavor. Must actually call the function to ensure it's not a stub.
     * (Always try wide version first so WinNT can process codepage correctly.)
     */

    if (0 == f_use)
    {
        unsigned short dummy;

        if (0 != GetStringTypeW(CT_CTYPE1, L"\0", 1, &dummy))
            f_use = USE_W;

        else if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
            f_use = USE_A;
    }

    /* Use "A" version */

    if (USE_A == f_use || f_use == 0)
    {
        char *cbuffer = NULL;
        int ret;
        int AnsiCP;

        if (0 == lcid)
            lcid = plocinfo->locinfo->lc_handle[LC_CTYPE];
        if (0 == code_page)
            code_page = plocinfo->locinfo->lc_codepage;

        if ( -1 == (AnsiCP = __ansicp(lcid)))
            return FALSE;
        /* If current code-page is not ansi code page, convert it to ansi code page
         * as GetStringTypeA uses ansi code page to find the strig type.
         */
        if ( AnsiCP != code_page)
        {
            cbuffer = __convertcp(code_page, AnsiCP, lpSrcStr, &cchSrc, NULL, 0);
            if (cbuffer == NULL)
                return FALSE;
            lpSrcStr = cbuffer;
        }

        ret = GetStringTypeA(lcid, dwInfoType, lpSrcStr, cchSrc, lpCharType);
        if ( cbuffer != NULL)
            _free_crt(cbuffer);
        return ret;
    }

    /* Use "W" version */

    if (USE_W == f_use)
    {
        int retval1;
        int buff_size;
        wchar_t *wbuffer;
        BOOL retval2 = FALSE;

        /*
         * Convert string and return the requested information. Note that
         * we are converting to a wide character string so there is not a
         * one-to-one correspondence between number of multibyte chars in the
         * input string and the number of wide chars in the buffer. However,
         * there had *better be* a one-to-one correspondence between the
         * number of multibyte characters and the number of WORDs in the
         * return buffer.
         */

        /*
         * Use __lc_codepage for conversion if code_page not specified
         */

        if (0 == code_page)
            code_page = plocinfo->locinfo->lc_codepage;

        /* find out how big a buffer we need */
        if ( 0 == (buff_size = MultiByteToWideChar( code_page,
                                                    bError ?
                                                        MB_PRECOMPOSED |
                                                        MB_ERR_INVALID_CHARS
                                                        : MB_PRECOMPOSED,
                                                    lpSrcStr,
                                                    cchSrc,
                                                    NULL,
                                                    0 )) )
            return FALSE;

        /* allocate enough space for wide chars */
        wbuffer = (wchar_t *)_calloca( sizeof(wchar_t), buff_size );
        if ( wbuffer == NULL ) {
            return FALSE;
        }
        (void)memset( wbuffer, 0, sizeof(wchar_t) * buff_size );

        /* do the conversion */
        if ( 0 != (retval1 = MultiByteToWideChar( code_page,
                                                 MB_PRECOMPOSED,
                                                 lpSrcStr,
                                                 cchSrc,
                                                 wbuffer,
                                                 buff_size )) )
            /* obtain result */
            retval2 = GetStringTypeW( dwInfoType,
                                      wbuffer,
                                      retval1,
                                      lpCharType );

        _freea(wbuffer);

        return retval2;
    }
    else   /* f_use is neither USE_A nor USE_W */
        return FALSE;
}
Ejemplo n.º 22
0
BOOL __cdecl __crtGetStringTypeA(
    DWORD    dwInfoType,
    LPCSTR   lpSrcStr,
    int      cchSrc,
    LPWORD   lpCharType,
    int      code_page,
    int      lcid
    )
{
    static int f_use = 0;

    /* 
     * Look for unstubbed 'preferred' flavor. Otherwise use available flavor.
     * Must actually call the function to ensure it's not a stub.
     */
    
    if (0 == f_use)
    {
        unsigned short dummy;

    	if (0 != GetStringTypeA(0, CT_CTYPE1, "\0", 1, &dummy))
            f_use = USE_A;

    	else if (0 != GetStringTypeW(CT_CTYPE1, L"\0", 1, &dummy))
            f_use = USE_W;

        else
            return FALSE;
    }

    /* Use "A" version */

    if (USE_A == f_use)
    {
        if (0 == lcid)
            lcid = __lc_handle[LC_CTYPE];

        return GetStringTypeA(lcid, dwInfoType, lpSrcStr, cchSrc, lpCharType);
    }

    /* Use "W" version */

    if (USE_W == f_use)
    {
        int retval;
        int buff_size;
        BOOL retbool = FALSE;
        wchar_t *wbuffer = NULL;

        /*
         * Convert string and return the requested information. Note that 
         * we are converting to a wide character string so there is not a 
         * one-to-one correspondence between number of multibyte chars in the 
         * input string and the number of wide chars in the buffer. However, 
         * there had *better be* a one-to-one correspondence between the 
         * number of multibyte characters and the number of WORDs in the
         * return buffer.
         */
         
        /*
         * Use __lc_codepage for conversion if code_page not specified
         */

        if (0 == code_page)
            code_page = __lc_codepage;

        /* find out how big a buffer we need */
        if (0 == (buff_size = MultiByteToWideChar(code_page, 
            MB_PRECOMPOSED|MB_ERR_INVALID_CHARS, lpSrcStr, cchSrc, NULL, 0)))
            goto done;

        /* allocate enough space for wide chars */
        if (NULL == (wbuffer = (wchar_t *)_calloc_crt(sizeof(wchar_t), buff_size)))
            goto done;

        /* do the conversion */
        if (0 == (retval = MultiByteToWideChar(code_page, 
            MB_PRECOMPOSED, lpSrcStr, cchSrc, wbuffer, buff_size)))
            goto done;

        /* obtain result */
        retbool = GetStringTypeW(dwInfoType, wbuffer, retval, lpCharType);

done:
        _free_crt(wbuffer);
        return retbool;
    }
}
Ejemplo n.º 23
0
BOOLEAN
NTAPI
PasswordFilter(
    PUNICODE_STRING UserName,
    PUNICODE_STRING FullName,
    PUNICODE_STRING Password,
    BOOLEAN SetOperation
    )
/*++

Routine Description:

    This (optional) routine is notified of a password change.

Arguments:

    UserName - Name of user whose password changed

    FullName - Full name of the user whose password changed

    NewPassword - Cleartext new password for the user

    SetOperation - TRUE if the password was SET rather than CHANGED

Return Value:

    TRUE if the specified Password is suitable (complex, long, etc).
     The system will continue to evaluate the password update request
     through any other installed password change packages.

    FALSE if the specified Password is unsuitable. The password change
     on the specified account will fail.

--*/
{

    BOOLEAN bComplex = FALSE; // assume the password in not complex enough
    DWORD cchPassword;
    DWORD i;
    DWORD j;
    DWORD count;
    DWORD dwNum = 0;
    DWORD dwUpper = 0;
    DWORD dwLower = 0;
    DWORD dwSpecialChar = 0 ;
    PCHAR token ;
    CHAR _password[PWLEN+1];
    CHAR _username[UNLEN+1];
    PCHAR _fullname = NULL;
    WORD CharType[PWLEN+1];
    PCHAR TempString;

    //
    // If the password was explicitly set, allow it through.
    //

    if (SetOperation)
    {
        bComplex = TRUE;
        goto end;
    }

    //
    // Make sure the password and username will fit in our local buffers
    //

    if (Password->Length > PWLEN * sizeof(WCHAR))
    {
        goto end;
    }

    if (UserName->Length > UNLEN * sizeof(WCHAR))
    {
        goto end;
    }

    _fullname = HeapAlloc(GetProcessHeap(), 0, FullName->Length + sizeof(WCHAR));
    if (_fullname == NULL)
    {
        goto end;
    }


    //
    // check if the password is complex enough for our liking by
    // checking that at least two of the four character types are
    // present.
    //

    cchPassword = Password->Length / sizeof(WCHAR);


    if(GetStringTypeW(
        CT_CTYPE1,
        Password->Buffer,
        cchPassword,
        CharType
        )) {

        for(i = 0 ; i < cchPassword ; i++) {

            //
            // keep track of what type of characters we have encountered
            //

            if(CharType[i] & C1_DIGIT) {
                dwNum = 1;
                continue;
            }

            if(CharType[i] & C1_UPPER) {
                dwUpper = 1;
                continue;
            }

            if(CharType[i] & C1_LOWER) {
                dwLower = 1;
                continue;
            }

        } // for

        //
        // Indicate whether we encountered enough password complexity
        //

        if( (dwNum + dwLower + dwUpper) < 2) {

            bComplex = FALSE ;
            goto end ;

        } else {

            //
            // now we resort to more complex checking
            //
            wcstombs(_password, Password->Buffer, PWLEN+1) ;
            wcstombs(_username, UserName->Buffer, UNLEN+1) ;
            wcstombs(_fullname, FullName->Buffer, 1+FullName->Length/sizeof(WCHAR)) ;

            _strupr(_password) ;
            _password[Password->Length/sizeof(WCHAR)] = '\0' ;
            _strupr(_username) ;
            _username[UserName->Length/sizeof(WCHAR)] = '\0' ;
            _strupr(_fullname) ;
            _fullname[FullName->Length/sizeof(WCHAR)] = '\0' ;

            if (strpbrk (_password, "(`~!@#$%^&*_-+=|\\{}[]:;\"'<>,.?)") != NULL) {
                dwSpecialChar = 1 ;
            }

            if ((dwNum + dwLower + dwUpper + dwSpecialChar) < 3) {
                bComplex = FALSE ;
                goto end ;
            }

            if ((UserName->Length >= 3 * sizeof(WCHAR)) && strstr (_password, _username)) {

                bComplex = FALSE ;
                goto end ;
            }


            //
            // Tokenize the full name and check if the password is derived from it
            //

            token = LocalStrTok(_fullname, " ,.\t-_#",&TempString);
            while( token != NULL ) {

                if (lstrlenA(token) > 3 && strstr(_password, token)) {
                    bComplex = FALSE ;
                    goto end ;
                }

                token = LocalStrTok(NULL, " ,.\t-_#",&TempString);
            }

            bComplex = TRUE ;

        }


    } // if

end:

    ZeroMemory( CharType, Password->Length );
    ZeroMemory( _password, Password->Length );
    HeapFree(GetProcessHeap(), 0, _fullname);

    return bComplex;
}
Ejemplo n.º 24
0
  void* _Locale_ctype_create(const char * name) {
    char cname[_Locale_MAX_SIMPLE_NAME];
    char cp_name[MAX_CP_LEN+1];
    int NativeCP;
    unsigned char Buffer[256];
    unsigned char *ptr;
    unsigned short ctable[256];
    CPINFO CPInfo;
    int i;
    wchar_t *wbuffer;
    int BufferSize;

    _Locale_ctype_t *ltype=(_Locale_ctype_t*)malloc(sizeof(_Locale_ctype_t));
    if(!ltype) return ltype;
    memset(ltype, 0, sizeof(_Locale_ctype_t));

    __Extract_locale_name(name, LC_CTYPE, cname);

    if(__GetLCIDFromName(cname, &ltype->lcid, cp_name)==-1)
    { free(ltype); return NULL; }
    ltype->cp = atoi(cp_name);

    NativeCP=__intGetACP(ltype->lcid);
    if(NativeCP == 0)
      NativeCP=__intGetOCP(ltype->lcid);

    /* Make table with all characters. */
    for(i = 0; i < 256; ++i) Buffer[i] = i;

    if(!GetCPInfo(NativeCP, &CPInfo)) { free(ltype); return NULL; }

    if(CPInfo.MaxCharSize > 1) {
      for(ptr=(unsigned char*)CPInfo.LeadByte; *ptr && *(ptr+1); ptr+=2)
	      for(i=*ptr; i <= *(ptr+1); ++i) Buffer[i] = 0;
    }

    if(NativeCP != ltype->cp) {
    	OSVERSIONINFO ver_info;
        ver_info.dwOSVersionInfoSize = sizeof(ver_info);
    	GetVersionEx(&ver_info);
    	if(ver_info.dwPlatformId == VER_PLATFORM_WIN32_NT) {
	      // Convert character sequence to Unicode.
	      BufferSize = MultiByteToWideChar(ltype->cp, MB_PRECOMPOSED, (const char*)Buffer, 256, NULL, 0);
	      wbuffer = (wchar_t*)malloc(BufferSize*sizeof(wchar_t));
	      if(!MultiByteToWideChar(ltype->cp, MB_PRECOMPOSED, (const char*)Buffer, 256, wbuffer, BufferSize))
	      { free(wbuffer); free(ltype); return NULL; }

	      GetStringTypeW(CT_CTYPE1, wbuffer, 256, ctable);

	      for(i = 0; i < 256; ++i)
	        ltype->ctable[i]=(unsigned int)ctable[i];

        if(CPInfo.MaxCharSize > 1) {
	        for(ptr=(unsigned char*)CPInfo.LeadByte; *ptr && *(ptr+1); ptr+=2)
		        for(i=*ptr; i <= *(ptr+1); i++) ltype->ctable[i] = _LEADBYTE;
        }

	      free(wbuffer);
	    }
    	else {
	      unsigned char TargetBuffer[256];
	      GetStringTypeA(ltype->lcid, CT_CTYPE1, (const char*)Buffer, 256, ctable);

	      // Convert character sequence to target code page.
	      BufferSize = MultiByteToWideChar(NativeCP, MB_PRECOMPOSED, (const char*)Buffer, 256, NULL, 0);
	      wbuffer = (wchar_t*)malloc(BufferSize*sizeof(wchar_t));
	      if(!MultiByteToWideChar(NativeCP, MB_PRECOMPOSED, (const char*)Buffer, 256, wbuffer, BufferSize))
	      { free(wbuffer); free(ltype); return NULL; }
	      if(!WideCharToMultiByte(ltype->cp, WC_COMPOSITECHECK | WC_SEPCHARS, wbuffer, BufferSize, (char*)TargetBuffer, 256, NULL, FALSE))
	      { free(wbuffer); free(ltype); return NULL; }

	      free(wbuffer);

	      // Translate ctype table.
	      for(i = 0; i < 256; ++i) {
		      if(!TargetBuffer[i]) continue;
		      ltype->ctable[TargetBuffer[i]] = ctable[i];
	      }

	      // Mark lead byte.
	      if(!GetCPInfo(ltype->cp, &CPInfo)) { free(ltype); return NULL; }

        if(CPInfo.MaxCharSize > 1) {
	        for(ptr=(unsigned char*)CPInfo.LeadByte; *ptr && *(ptr+1); ptr+=2)
		        for(i=*ptr; i <= *(ptr+1); ++i) ltype->ctable[i] = _LEADBYTE;
        }
	    }
    }
    else {
	    GetStringTypeA(ltype->lcid, CT_CTYPE1, (const char*)Buffer, 256, ctable);
	    for(i = 0; i < 256; ++i)
	      ltype->ctable[i]=(unsigned int)ctable[i];

      if(CPInfo.MaxCharSize > 1) {
	      for(ptr=(unsigned char*)CPInfo.LeadByte; *ptr && *(ptr+1); ptr+=2)
	        for(i=*ptr; i <= *(ptr+1); ++i) ltype->ctable[i] = _LEADBYTE;
      }
    }
    return ltype;
  }
Ejemplo n.º 25
0
void CCrystalParser::WrapLine( int nLineIndex, int nMaxLineWidth, int *anBreaks, int &nBreaks )
{
	// The parser must be attached to a view!
	ASSERT( m_pTextView );

	int			nLineLength = m_pTextView->GetLineLength( nLineIndex );
	int			nTabWidth = m_pTextView->GetTabSize();
	int			nLineCharCount = 0;
	int			nCharCount = 0;
	LPCTSTR	szLine = m_pTextView->GetLineChars( nLineIndex );
	int			nLastBreakPos = 0;
	int			nLastCharBreakPos = 0;
	bool		bBreakable = false;
	TCHAR		ch;
	int			nCharWidth = m_pTextView->GetCharWidth();
	WORD		wCharType;

	for( int i = 0; i < nLineLength; i++ )
	{
		ch = szLine[i]; 
		// remember position of whitespace for wrap
		if( bBreakable )
		{
			nLastBreakPos = i;
			nLastCharBreakPos = nCharCount;
			bBreakable = false;
		}

		// increment char counter (evtl. expand tab)
		if( ch == _T('\t') )
		{
			nLineCharCount+= (nTabWidth - nCharCount % nTabWidth);
			nCharCount+= (nTabWidth - nCharCount % nTabWidth);
			// remember whitespace
			bBreakable = true;
		}
		else
		{
#ifndef _UNICODE
			if( IsDBCSLeadByte((BYTE)ch) )
			{
				nLineCharCount += 2;
				nCharCount += 2;
				GetStringTypeA(LOCALE_USER_DEFAULT,CT_CTYPE3, &szLine[i], 2, &wCharType);
				// remember whitespace
				if( (wCharType & (C3_IDEOGRAPH | C3_HIRAGANA | C3_KATAKANA)))
					bBreakable = true;
			}
			else
			{
				nLineCharCount ++;
				nCharCount ++;
				// remember whitespace
				if( ch == _T(' ') )
					bBreakable = true;
			}
#else
			if (ch & 0xff80)
			{
				int n = m_pTextView->GetCharWidthFromChar(ch) / nCharWidth;
				nLineCharCount += n;
				nCharCount += n;
				GetStringTypeW(CT_CTYPE3, &ch, 1, &wCharType);
				// remember whitespace
				if( wCharType & (C3_IDEOGRAPH | C3_HIRAGANA | C3_KATAKANA) )
					bBreakable = true;
			}
			else
			{
				nLineCharCount ++;
				nCharCount ++;
				// remember whitespace
				if( ch == _T(' ') )
					bBreakable = true;
			}
#endif
		}

		// wrap line
		if( nLineCharCount >= nMaxLineWidth )
		{
			// if no wrap position found, but line is to wide, 
			// wrap at current position
			if( nLastBreakPos == 0 )
			{
				nLastBreakPos = i;
				nLastCharBreakPos = nCharCount;
			}
			if( anBreaks )
				anBreaks[nBreaks++] = nLastBreakPos;
			else
				nBreaks++;

			nLineCharCount = nCharCount - nLastCharBreakPos;
			nLastBreakPos = 0;
		}

#ifndef _UNICODE
		if (IsDBCSLeadByte((BYTE)ch))
			i++;
#endif
	}
}
Ejemplo n.º 26
0
/* Convert the incomplete win32 table to some slightly more useful data */
static void classify(LPCWSTR lpString, WORD *chartype, DWORD uCount)
{
    unsigned i, j;
    GetStringTypeW(CT_CTYPE2, lpString, uCount, chartype);
    for (i = 0; i < uCount; ++i)
        switch (chartype[i])
        {
        case C2_LEFTTORIGHT:
            chartype[i] = L;
            break;
        case C2_RIGHTTOLEFT:
            chartype[i] = AL;
            for (j = 0; j < sizeof(Rs)/sizeof(WCHAR); ++j)
                if (Rs[j] == lpString[i])
                {
                    chartype[i] = R;
                    break;
                }
            break;

        case C2_EUROPENUMBER:
            chartype[i] = EN;
            break;
        case C2_EUROPESEPARATOR:
            chartype[i] = ES;
            break;
        case C2_EUROPETERMINATOR:
            chartype[i] = ET;
            break;
        case C2_ARABICNUMBER:
            chartype[i] = AN;
            break;
        case C2_COMMONSEPARATOR:
            chartype[i] = CS;
            break;
        case C2_BLOCKSEPARATOR:
            chartype[i] = B;
            break;
        case C2_SEGMENTSEPARATOR:
            chartype[i] = S;
            break;
        case C2_WHITESPACE:
            chartype[i] = WS;
            break;
        case C2_OTHERNEUTRAL:
            switch (lpString[i])
            {
            case 0x202A:
                chartype[i] = LRE;
                break;
            case 0x202B:
                chartype[i] = RLE;
                break;
            case 0x202C:
                chartype[i] = PDF;
                break;
            case 0x202D:
                chartype[i] = LRO;
                break;
            case 0x202E:
                chartype[i] = RLO;
                break;
            default:
                chartype[i] = ON;
                break;
            }
            break;
        case C2_NOTAPPLICABLE:
            chartype[i] = NSM;
            for (j = 0; j < sizeof(BNs)/sizeof(WCHAR); ++j)
                if (BNs[j] == lpString[i])
                {
                    chartype[i] = BN;
                    break;
                }
            break;

        default:
            /* According to BiDi spec, unassigned characters default to L */
            FIXME("Unhandled character type: %04x\n", chartype[i]);
            chartype[i] = L;
            break;
        }
}
BOOL __cdecl __crtGetStringTypeW(
        DWORD    dwInfoType,
        LPCWSTR  lpSrcStr,
        int      cchSrc,
        LPWORD   lpCharType,
        int      code_page,
        int      lcid
        )
{
        static int f_use = 0;

        /*
         * Look for unstubbed 'preferred' flavor. Otherwise use available flavor.
         * Must actually call the function to ensure it's not a stub.
         */

        if (0 == f_use)
        {
            unsigned short dummy;

            if (0 != GetStringTypeW(CT_CTYPE1, L"\0", 1, &dummy))
                f_use = USE_W;

            else if (0 != GetStringTypeA(0, CT_CTYPE1, "\0", 1, &dummy))
                f_use = USE_A;

            else
                return FALSE;
        }

        /* Use "W" version */

        if (USE_W == f_use)
        {
            return GetStringTypeW(dwInfoType, lpSrcStr, cchSrc, lpCharType);
        }

        /* Use "A" version */

        if (USE_A == f_use)
        {
            int buff_size;
            BOOL retbool;
            unsigned char *buffer;
            WORD * pwCharInfo;

            /*
             * Convert string and return the requested information. Note that
             * we are converting to a multibyte string so there is not a
             * one-to-one correspondence between number of wide chars in the
             * input string and the number of *bytes* in the buffer. However,
             * there had *better be* a one-to-one correspondence between the
             * number of wide characters and the number of WORDs in the
             * return buffer.
             */

            /*
             * Use __lc_codepage for conversion if code_page not specified
             */

            if (0 == code_page)
                code_page = __lc_codepage;

            /* find out how big a buffer we need */
            if ( 0 == (buff_size = WideCharToMultiByte( code_page,
                                                        WC_COMPOSITECHECK |
                                                            WC_SEPCHARS,
                                                        lpSrcStr,
                                                        cchSrc,
                                                        NULL,
                                                        0,
                                                        NULL,
                                                        NULL )) )
                return FALSE;

            /* allocate enough space for chars */
            __try {
                buffer = (unsigned char *)_alloca( sizeof(char) * buff_size );
                (void)memset( buffer, 0, sizeof(char) * buff_size );
            }
            __except( EXCEPTION_EXECUTE_HANDLER ) {
                buffer = NULL;
            }

            if ( buffer == NULL )
                return FALSE;

            /* do the conversion */
            if ( 0 == WideCharToMultiByte( code_page,
                                           WC_COMPOSITECHECK | WC_SEPCHARS,
                                           lpSrcStr,
                                           cchSrc,
                                           buffer,
                                           buff_size,
                                           NULL,
                                           NULL ) )
                return FALSE;

            /* allocate enough space for result (+1 for sanity check) */
            __try {
                pwCharInfo = (WORD *)_alloca( sizeof(WORD) * (buff_size + 1) );
            }
            __except( EXCEPTION_EXECUTE_HANDLER ) {
                pwCharInfo = NULL;
            }

            if ( pwCharInfo == NULL )
                return FALSE;

            /* do we use default lcid */
            if (0 == lcid)
                lcid = __lc_handle[LC_CTYPE];

            /* set to known value */
            pwCharInfo[cchSrc - 1] = pwCharInfo[cchSrc] = 0xFFFF;

            /* obtain result */
            retbool = GetStringTypeA( lcid, dwInfoType, buffer, buff_size,
                                      pwCharInfo );

            /*
             * GetStringTypeA does not reveal how many WORDs have been
             * modifed - to be safe we use another buffer and then
             * verify that EXACTLY cchSrc WORDs were modified. Note that
             * not all multibyte LCID/codepage combos are guaranteed to work.
             */

            if (pwCharInfo[cchSrc - 1] == 0xFFFF || pwCharInfo[cchSrc] != 0xFFFF)
                return FALSE;

            memmove(lpCharType, pwCharInfo, cchSrc * sizeof(WORD));

            return retbool;
        }
Ejemplo n.º 28
0
/*********************************************************************
 *		_setmbcp (MSVCRT.@)
 * @implemented
 */
int CDECL _setmbcp(int cp)
{
  int newcp;
  CPINFO cpi;
  BYTE *bytes;
  WORD chartypes[256];
  WORD *curr_type;
  char bufA[256];
  WCHAR bufW[256];
  int charcount;
  int ret;
  int i;

  TRACE("_setmbcp %d\n",cp);
  switch (cp)
  {
    case _MB_CP_ANSI:
      newcp = GetACP();
      break;
    case _MB_CP_OEM:
      newcp = GetOEMCP();
      break;
    case _MB_CP_LOCALE:
      newcp = MSVCRT___lc_codepage;
      break;
    case _MB_CP_SBCS:
      newcp = 20127;   /* ASCII */
      break;
    default:
      newcp = cp;
      break;
  }

  if (!GetCPInfo(newcp, &cpi))
  {
    ERR("Codepage %d not found\n", newcp);
    __set_errno(EINVAL);
    return -1;
  }

  /* setup the _mbctype */
  memset(_mbctype, 0, sizeof(_mbctype));

  bytes = cpi.LeadByte;
  while (bytes[0] || bytes[1])
  {
    for (i = bytes[0]; i <= bytes[1]; i++)
      _mbctype[i + 1] |= _M1;
    bytes += 2;
  }

  if (cpi.MaxCharSize > 1)
  {
    /* trail bytes not available through kernel32 but stored in a structure in msvcrt */
    struct cp_extra_info_t *cpextra = g_cpextrainfo;

    g_mbcp_is_multibyte = 1;
    while (TRUE)
    {
      if (cpextra->cp == 0 || cpextra->cp == newcp)
      {
        if (cpextra->cp == 0)
          ERR("trail bytes data not available for DBCS codepage %d - assuming all bytes\n", newcp);

        bytes = cpextra->TrailBytes;
        while (bytes[0] || bytes[1])
        {
          for (i = bytes[0]; i <= bytes[1]; i++)
            _mbctype[i + 1] |= _M2;
          bytes += 2;
        }
        break;
      }
      cpextra++;
    }
  }
  else
    g_mbcp_is_multibyte = 0;

  /* we can't use GetStringTypeA directly because we don't have a locale - only a code page
   */
  charcount = 0;
  for (i = 0; i < 256; i++)
    if (!(_mbctype[i + 1] & _M1))
      bufA[charcount++] = i;

  ret = MultiByteToWideChar(newcp, 0, bufA, charcount, bufW, charcount);
  if (ret != charcount)
    ERR("MultiByteToWideChar of chars failed for cp %d, ret=%d (exp %d), error=%d\n", newcp, ret, charcount, GetLastError());

  GetStringTypeW(CT_CTYPE1, bufW, charcount, chartypes);

  curr_type = chartypes;
  for (i = 0; i < 256; i++)
    if (!(_mbctype[i + 1] & _M1))
    {
	if ((*curr_type) & C1_UPPER)
	    _mbctype[i + 1] |= _SBUP;
	if ((*curr_type) & C1_LOWER)
	    _mbctype[i + 1] |= _SBLOW;
	curr_type++;
    }

  if (newcp == 932)   /* CP932 only - set _MP and _MS */
  {
    /* On Windows it's possible to calculate the _MP and _MS from CT_CTYPE1
     * and CT_CTYPE3. But as of Wine 0.9.43 we return wrong values what makes
     * it hard. As this is set only for codepage 932 we hardcode it what gives
     * also faster execution.
     */
    for (i = 161; i <= 165; i++)
      _mbctype[i + 1] |= _MP;
    for (i = 166; i <= 223; i++)
      _mbctype[i + 1] |= _MS;
  }

  MSVCRT___lc_collate_cp = MSVCRT___lc_codepage = newcp;
  TRACE("(%d) -> %d\n", cp, MSVCRT___lc_codepage);
  return 0;
}