Example #1
0
bool voikko_is_nonword(const wchar_t * word, size_t nchars) {
	// If X is a character (possibly other than '.'), then the following
	// patterns (URLs and email addresses) will be considered non-words:
	//   X*//X*.X+
	//   X*@X+.X+
	//   www.X+.X+
	
	if (nchars < 4) return false;
	
	const wchar_t * i = wmemchr(word, L'/', nchars - 3);
	if (i && i[1] == L'/' && wmemchr(i + 1, L'.', nchars - (i - word) - 2)) {
		return true;
	}
	
	i = wmemchr(word, L'@', nchars - 3);
	if (i && i[1] != L'.' && wmemchr(i + 1, L'.', nchars - (i - word) - 2)) {
		return true;
	}
	
	if (nchars < 7) {
		return false;
	}
	if ((wcsncmp(L"www.", word, 4) == 0) &&
	    word[4] != L'.' &&
	    wmemchr(word + 5, L'.', nchars - 5)) {
		return true;
	}
	
	return false;
}
Example #2
0
int main( void )
{
    TESTCASE( wmemchr( wabcde, L'c', 5 ) == &wabcde[2] );
    TESTCASE( wmemchr( wabcde, L'a', 1 ) == &wabcde[0] );
    TESTCASE( wmemchr( wabcde, L'a', 0 ) == NULL );
    TESTCASE( wmemchr( wabcde, L'\0', 5 ) == NULL );
    TESTCASE( wmemchr( wabcde, L'\0', 6 ) == &wabcde[5] );
    return TEST_RESULTS;
}
Example #3
0
static __inline int
inccl(const struct ccl *ccl, wint_t wi)
{

	if (ccl->compl) {
		return (wmemchr(ccl->start, wi, ccl->end - ccl->start)
		    == NULL);
	} else {
		return (wmemchr(ccl->start, wi, ccl->end - ccl->start) != NULL);
	}
}
Example #4
0
static int
processLine (char *line, void *data) {
  const char *string = line;
  size_t length = strlen(string);
  const char *byte = string;

  size_t count = length + 1;
  wchar_t characters[count];
  wchar_t *character = characters;

  convertUtf8ToWchars(&byte, &character, count);
  length = character - characters;
  character = characters;

  while (1) {
    const wchar_t *end = wmemchr(character, FF, length);
    if (!end) break;

    count = end - character;
    if (!processCharacters(character, count, *end, data)) return 0;

    count += 1;
    character += count;
    length -= count;
  }
  if (!processCharacters(character, length, '\n', data)) return 0;

  if (opt_forceOutput)
    if (!flushOutputStream(data))
      return 0;

  return 1;
}
Example #5
0
int
brlDotNumberToIndex (wchar_t number, int *index) {
  const wchar_t *character = wmemchr(brlDotNumbers, number, ARRAY_COUNT(brlDotNumbers));
  if (!character) return 0;
  *index = character - brlDotNumbers;
  return 1;
}
Example #6
0
getcchar(const cchar_t *wcval,
	 wchar_t *wch,
	 attr_t *attrs,
	 short *color_pair,
	 void *opts)
{
    wchar_t *wp;
    int len;
    int code = ERR;

    TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
		      wcval, wch, attrs, color_pair, opts));

    if (opts == NULL) {
	len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
	    ? wp - wcval->chars
	    : CCHARW_MAX;

	if (wch == NULL) {
	    code = len;
	} else if (attrs == 0 || color_pair == 0) {
	    code = ERR;
	} else if (len >= 0) {
	    *attrs = AttrOf(*wcval) & A_ATTRIBUTES;
	    *color_pair = GetPair(*wcval);
	    wmemcpy(wch, wcval->chars, (unsigned) len);
	    wch[len] = L'\0';
	    code = OK;
	}
    }

    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}
Example #7
0
OMRawStorage* 
OMXMLStorage::openNewDataStream(const wchar_t* uri)
{
    TRACE("OMXMLStorage::openNewDataStream");
    PRECONDITION("XML document raw storage has filename", _storage->fileName() != 0);

    // uri is assumed to be 'stream directory' / 'stream file name' as
    // created in getDataStreamEntityValue()

    OMDiskRawStorage* storage = 0;

    wchar_t* base = getBaseFilePath(_storage->fileName());


    // start by creating the directory
    wchar_t* workBuffer = new wchar_t[wcslen(uri) + 1];
    wcscpy(workBuffer, uri);
    wchar_t* sep = wmemchr(workBuffer, L'/', wcslen(uri));
    ASSERT("New DataStream uri starts with a directory", sep != 0);
    *sep = L'\0';
    wchar_t* filepath = new wchar_t[wcslen(workBuffer) + 1];
    wcsconvertURItoFilepath(workBuffer, filepath);
    wchar_t* fullFilepath = new wchar_t[wcslen(base) + wcslen(filepath) + 1];
    wcscpy(fullFilepath, base);
    wcscat(fullFilepath, filepath);
    wmkdir(fullFilepath);
    delete [] workBuffer;
    delete [] filepath;
    delete [] fullFilepath;

    // remove the file and then open new modify
    filepath = new wchar_t[wcslen(uri) + 1];
    wcsconvertURItoFilepath(uri, filepath);
    fullFilepath = new wchar_t[wcslen(base) + wcslen(filepath) + 1];
    wcscpy(fullFilepath, base);
    wcscat(fullFilepath, filepath);
    wremove(fullFilepath);
    try
    {
        storage = OMDiskRawStorage::openNewModify(fullFilepath);
    }
    catch (...)
    {
        storage = 0;
    }

    delete [] filepath;
    delete [] fullFilepath;
    delete [] base;
    
    return storage;
}
void SuggestionGeneratorSoftHyphens::generate(SuggestionStatus * s) const {
	const size_t wlen = s->getWordLength();
	const wchar_t * word = s->getWord();
	const wchar_t * softHyphen = wmemchr(word, L'\u00AD', wlen);
	if (softHyphen) {
		wchar_t * buffer = new wchar_t[wlen];
		size_t j = 0;
		for (size_t i = 0; i < wlen; ++i) {
			if (word[i] != L'\u00AD') {
				buffer[j++] = word[i];
			}
		}
		buffer[j] = L'\0';
		SuggestionGeneratorCaseChange::suggestForBuffer(morAnalyzer, s, buffer, j);
		delete[] buffer;
	}
}
Example #9
0
OMUniqueObjectIdentification 
OMXMLStorage::getMetaDefIdFromQSymbol(const wchar_t* qSymbol) const
{
    TRACE("OMXMLStorage::getMetaDefIdFromQSymbol");
    
    // if the qSymbol refers to a non-baseline metadef then it
    // must be in the qSymbolMap; otherwise it is a baseline qSymbol
    OMUniqueObjectIdentification id = _metaDefIdMap.getId(qSymbol);
    if (id == nullOMUniqueObjectIdentification)
    {
        // support qualified baseline symbols
        // users __should__ use just the symbol for baseline metadefs
        const wchar_t* spc = wmemchr(qSymbol, L' ', wcslen(qSymbol));
        ASSERT("Valid QSymbol has space", spc != 0);
        id = getBaselineMetaDefId(spc + 1);
    }
    
    return id;
}
Example #10
0
static int has_invalid_null_termination(const ErlNifBinary *path) {
    const WCHAR *null_pos, *end_pos;

    null_pos = wmemchr((const WCHAR*)path->data, L'\0', path->size);
    end_pos = (const WCHAR*)&path->data[path->size] - 1;

    if(null_pos == NULL) {
        return 1;
    }

    /* prim_file:internal_name2native sometimes feeds us data that is "doubly"
     * NUL-terminated, so we'll accept any number of trailing NULs so long as
     * they aren't interrupted by anything else. */
    while(null_pos < end_pos && (*null_pos) == L'\0') {
        null_pos++;
    }

    return null_pos != end_pos;
}
TInt CTestLibcwchar::wmemchr2L(  )
    {

    wchar_t ws1[50]=L"abcdefghij",*retval;
	
	retval = wmemchr(ws1,L'x',50);

	INFO_PRINTF2(_L("wmemchr2 return is %d"),retval);

	if(retval != NULL)
		{
		return KErrGeneral;
		}
	else
		{
		return KErrNone;
		}
    
    }
Example #12
0
getcchar(const cchar_t *wcval,
	 wchar_t *wch,
	 attr_t *attrs,
	 short *color_pair,
	 void *opts)
{
    wchar_t *wp;
    int len;
    int code = ERR;

    TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
		      (const void *) wcval,
		      (void *) wch,
		      (void *) attrs,
		      (void *) color_pair,
		      opts));

    if (opts == NULL) {
	len = ((wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
	       ? (int) (wp - wcval->chars)
	       : CCHARW_MAX);

	if (wch == NULL) {
	    /*
	     * If the value is a null, set the length to 1.
	     * If the value is not a null, return the length plus 1 for null.
	     */
	    code = (len < CCHARW_MAX) ? (len + 1) : CCHARW_MAX;
	} else if (attrs == 0 || color_pair == 0) {
	    code = ERR;
	} else if (len >= 0) {
	    *attrs = AttrOf(*wcval) & A_ATTRIBUTES;
	    *color_pair = (short) GetPair(*wcval);
	    wmemcpy(wch, wcval->chars, (unsigned) len);
	    wch[len] = L'\0';
	    code = OK;
	}
    }

    TR(TRACE_CCALLS, (T_RETURN("%d"), code));
    return (code);
}
Example #13
0
static const lua_WChar *lmemfind (const lua_WChar *s1, size_t l1,
                               const lua_WChar *s2, size_t l2) {
  if (l2 == 0) return s1;  /* empty strings are everywhere */
  else if (l2 > l1) return NULL;  /* avoids a negative `l1' */
  else {
    const lua_WChar *init;  /* to search for a `*s2' inside `s1' */
    l2--;  /* 1st char will be checked by `memchr' */
    l1 = l1-l2;  /* `s2' cannot be found after that */
    while (l1 > 0 && (init = (const lua_WChar *)wmemchr(s1, *s2, l1)) != NULL) {
      init++;   /* 1st char is already checked */
      if (wmemcmp(init, s2+1, l2) == 0)
        return init-1;
      else {  /* correct `l1' and `s1' to try again */
        l1 -= init-s1;
        s1 = init;
      }
    }
    return NULL;  /* not found */
  }
}
TInt CTestLibcwchar::wmemchr1L(  )
    {

    wchar_t ws1[50]=L"abcdefghij",*retval;
	
	retval = wmemchr(ws1,L'c',10);

	INFO_PRINTF1(_L("wmemchr1 result is"));

	for(int i=0;i<9;i++)
		{
		INFO_PRINTF3(_L("retval[%d]=%x"),i,retval[i]);
		if(retval[i] != ws1[i+2])
			{
			return KErrGeneral;
			}
		}
	
	return KErrNone;
    
    }
Example #15
0
void test_wmemchr( void )
{
    wchar_t* dest;
    wint_t result;
    wint_t ch = L'r';
    wchar_t str[] =   L"lazy";
    wchar_t string1[60] = L"The quick brown dog jumps over the lazy fox";

    wprintf( L"Wmemchr\n" );
    wprintf( L"String to be searched:\n\t\t%s\n", string1 );
    wprintf( L"\t\t%s\n\t\t%s\n\n", fmt1, fmt2 );

    wprintf( L"Search char:\t%c\n", ch );
    dest = wmemchr( string1, ch, sizeof( string1 ) );
    result = dest - string1 + 1;
    if( dest != NULL )
        wprintf( L"Result:\t\t%c found at position %d\n\n", ch, result );
    else
        wprintf( L"Result:\t\t%c not found\n\n" );
    return;
}
Example #16
0
/***********************************************************************
 *      WindowsTrimStringStart (combase.@)
 */
HRESULT WINAPI WindowsTrimStringStart(HSTRING str1, HSTRING str2, HSTRING *out)
{
    struct hstring_private *priv1 = impl_from_HSTRING(str1);
    struct hstring_private *priv2 = impl_from_HSTRING(str2);
    UINT32 start;

    TRACE("(%p, %p, %p)\n", str1, str2, out);

    if (!out || !str2 || !priv2->length)
        return E_INVALIDARG;
    if (!str1)
    {
        *out = NULL;
        return S_OK;
    }
    for (start = 0; start < priv1->length; start++)
    {
        if (!wmemchr(priv2->buffer, priv1->buffer[start], priv2->length))
            break;
    }
    return start ? WindowsCreateString(&priv1->buffer[start], priv1->length - start, out) :
                   WindowsDuplicateString(str1, out);
}
Example #17
0
/***********************************************************************
 *      WindowsTrimStringEnd (combase.@)
 */
HRESULT WINAPI WindowsTrimStringEnd(HSTRING str1, HSTRING str2, HSTRING *out)
{
    struct hstring_private *priv1 = impl_from_HSTRING(str1);
    struct hstring_private *priv2 = impl_from_HSTRING(str2);
    UINT32 len;

    TRACE("(%p, %p, %p)\n", str1, str2, out);

    if (!out || !str2 || !priv2->length)
        return E_INVALIDARG;
    if (!str1)
    {
        *out = NULL;
        return S_OK;
    }
    for (len = priv1->length; len > 0; len--)
    {
        if (!wmemchr(priv2->buffer, priv1->buffer[len - 1], priv2->length))
            break;
    }
    return (len < priv1->length) ? WindowsCreateString(priv1->buffer, len, out) :
                                   WindowsDuplicateString(str1, out);
}
Example #18
0
static TACommandVerdict wmemchr_cmd(TAThread thread,TAInputStream stream)
{
    wchar_t* s;
    wchar_t c;
    size_t n;
    wchar_t* res;
    
    // Prepare
    s = readPointer(&stream);
    c = readWChar(&stream);
    n = readSize(&stream);
    
    // Execute
    START_TARGET_OPERATION(thread);
    res = wmemchr( s, c, n );
    END_TARGET_OPERATION(thread);
    
    // Response
    writePointer(thread,res);
    sendResponse(thread);
    
    return taDefaultVerdict;
}
Example #19
0
int main()
{
    mbstate_t mb = {0};
    size_t s = 0;
    tm tm = {0};
    wint_t w = 0;
    ::FILE* fp = 0;
    __darwin_va_list va;
    char* ns = 0;
    wchar_t* ws = 0;
    static_assert((std::is_same<decltype(fwprintf(fp, L"")), int>::value), "");
    static_assert((std::is_same<decltype(fwscanf(fp, L"")), int>::value), "");
    static_assert((std::is_same<decltype(swprintf(ws, s, L"")), int>::value), "");
    static_assert((std::is_same<decltype(swscanf(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(vfwprintf(fp, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vfwscanf(fp, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vswprintf(ws, s, L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vswscanf(L"", L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vwprintf(L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(vwscanf(L"", va)), int>::value), "");
    static_assert((std::is_same<decltype(wprintf(L"")), int>::value), "");
    static_assert((std::is_same<decltype(wscanf(L"")), int>::value), "");
    static_assert((std::is_same<decltype(fgetwc(fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(fgetws(ws, 0, fp)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(fputwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(fputws(L"", fp)), int>::value), "");
    static_assert((std::is_same<decltype(fwide(fp, 0)), int>::value), "");
    static_assert((std::is_same<decltype(getwc(fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(getwchar()), wint_t>::value), "");
    static_assert((std::is_same<decltype(putwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(putwchar(L' ')), wint_t>::value), "");
    static_assert((std::is_same<decltype(ungetwc(L' ', fp)), wint_t>::value), "");
    static_assert((std::is_same<decltype(wcstod(L"", (wchar_t**)0)), double>::value), "");
    static_assert((std::is_same<decltype(wcstof(L"", (wchar_t**)0)), float>::value), "");
    static_assert((std::is_same<decltype(wcstold(L"", (wchar_t**)0)), long double>::value), "");
    static_assert((std::is_same<decltype(wcstol(L"", (wchar_t**)0, 0)), long>::value), "");
    static_assert((std::is_same<decltype(wcstoll(L"", (wchar_t**)0, 0)), long long>::value), "");
    static_assert((std::is_same<decltype(wcstoul(L"", (wchar_t**)0, 0)), unsigned long>::value), "");
    static_assert((std::is_same<decltype(wcstoull(L"", (wchar_t**)0, 0)), unsigned long long>::value), "");
    static_assert((std::is_same<decltype(wcscpy(ws, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsncpy(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscat(ws, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsncat(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscmp(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(wcscoll(L"", L"")), int>::value), "");
    static_assert((std::is_same<decltype(wcsncmp(L"", L"", s)), int>::value), "");
    static_assert((std::is_same<decltype(wcsxfrm(ws, L"", s)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcschr((wchar_t*)0, L' ')), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcscspn(L"", L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcslen(L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcspbrk((wchar_t*)0, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsrchr((wchar_t*)0, L' ')), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsspn(L"", L"")), size_t>::value), "");
    static_assert((std::is_same<decltype(wcsstr((wchar_t*)0, L"")), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcstok(ws, L"", (wchar_t**)0)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemchr((wchar_t*)0, L' ', s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemcmp(L"", L"", s)), int>::value), "");
    static_assert((std::is_same<decltype(wmemcpy(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemmove(ws, L"", s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wmemset(ws, L' ', s)), wchar_t*>::value), "");
    static_assert((std::is_same<decltype(wcsftime(ws, s, L"", &tm)), size_t>::value), "");
    static_assert((std::is_same<decltype(btowc(0)), wint_t>::value), "");
    static_assert((std::is_same<decltype(wctob(w)), int>::value), "");
    static_assert((std::is_same<decltype(mbsinit(&mb)), int>::value), "");
    static_assert((std::is_same<decltype(mbrlen("", s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(mbrtowc(ws, "", s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcrtomb(ns, L' ', &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(mbsrtowcs(ws, (const char**)0, s, &mb)), size_t>::value), "");
    static_assert((std::is_same<decltype(wcsrtombs(ns, (const wchar_t**)0, s, &mb)), size_t>::value), "");
}
Example #20
0
int
cpbLinearCopy (int column, int row) {
  int copied = 0;
  ScreenDescription screen;
  describeScreen(&screen);

  {
    int rightColumn = screen.cols - 1;
    size_t length;
    wchar_t *buffer = cpbReadScreen(&length, 0, beginRow, rightColumn, row);

    if (buffer) {
      if (column < rightColumn) {
        wchar_t *start = buffer + length;
        while (start != buffer) {
          if (*--start == WC_C('\r')) {
            start += 1;
            break;
          }
        }

        {
          int adjustment = (column + 1) - (buffer + length - start);
          if (adjustment < 0) length += adjustment;
        }
      }

      if (beginColumn) {
        wchar_t *start = wmemchr(buffer, WC_C('\r'), length);
        if (!start) start = buffer + length;
        if ((start - buffer) > beginColumn) start = buffer + beginColumn;
        if (start != buffer) wmemmove(buffer, start, (length -= start - buffer));
      }

      {
        const wchar_t *from = buffer;
        const wchar_t *end = from + length;
        wchar_t *to = buffer;
        int spaces = 0;
        int newlines = 0;

        while (from != end) {
          wchar_t character = *from++;

          switch (character) {
            case WC_C(' '):
              spaces += 1;
              continue;

            case WC_C('\r'):
              newlines += 1;
              continue;

            default:
              break;
          }

          if (newlines) {
            if ((newlines > 1) || (spaces > 0)) spaces = 1;
            newlines = 0;
          }

          while (spaces) {
            *to++ = WC_C(' ');
            spaces -= 1;
          }

          *to++ = character;
        }

        length = to - buffer;
      }

      if (cpbEndOperation(buffer, length)) copied = 1;
      free(buffer);
    }
  }

  return copied;
}
Example #21
0
_STD_BEGIN

#define ACSIZE	32	/* holds only prefix, m.s. digits */

int _WGetint(_WSft *px, void *pans)
	{	/* get an integer value for _WScanf */
	wchar_t ac[ACSIZE], *p;
	char seen = 0;
	wint_t ch;
	static const wchar_t digits[] = {
		L'0', L'1', L'2', L'3', L'4', L'5',
		L'6', L'7', L'8', L'9', L'a', L'b',
		L'c', L'd', L'e', L'f', L'A', L'B',
		L'C', L'D', L'E', L'F'};
	static const wchar_t flit[] = {
		L'd', L'i', L'o', L'u', L'x', L'X',
		L'p', L'\0'};
	static const char barr[] = {10, 0, 8, 10, 16, 16, 16};
	int base =
		barr[(const wchar_t *)wcschr(&flit[0], *px->s) - flit];
	int dlen;

	px->nget = 0 < px->width ? px->width : INT_MAX;
	p = ac, ch = WGETN(px);
	if (ch == L'+' || ch == L'-')
		*p++ = ch, ch = WGETN(px);
	if (ch == L'0')
		{	/* match possible prefix */
		seen = 1;
		*p++ = ch, ch = WGETN(px);
		if ((ch == L'x' || ch == L'X')
			&& (base == 0 || base == 16))
			base = 16, *p++ = ch, ch = WGETN(px), seen = 0;
		else if (base == 0)
			base = 8;
		}
	dlen = base == 0 || base == 10 ? 10
		: base == 8 ? 8 : 16 + 6;
	for (; ch == L'0'; seen = 1)
		ch = WGETN(px);
	if (seen)
		*p++ = L'0';
	for (; ch != WEOF && wmemchr(&digits[0], ch, dlen);
		ch = WGETN(px), seen = 1)
		if (p < &ac[ACSIZE - 1])
			*p++ = ch;
	WUNGETN(px, ch);
	if (!seen)
		return (p == ac && ch == WEOF ? EOF : 0);
	*p = L'\0';
	if (px->noconv)
		;
	else if (*px->s == L'd' || *px->s == L'i')
		{	/* deliver a signed integer */
		const _Longlong lval = _WStoll(ac, 0, base);

		px->stored = 1;
		switch (px->qual)
			{	/* store in specified integer type */
		case L'b':
			if (pans != 0)
				*(signed char *)pans = (signed char)lval;
			else
				*va_arg(px->ap, signed char *) = (signed char)lval;
			break;

		case L'q':
			if (pans != 0)
				*(_Longlong *)pans = lval;
			else
				*va_arg(px->ap, _Longlong *) = lval;
			break;

		case L'j':
			if (pans != 0)
				*(intmax_t *)pans = lval;
			else
				*va_arg(px->ap, intmax_t *) = lval;
			break;

		case L't':
			if (pans != 0)
				*(ptrdiff_t *)pans = (ptrdiff_t)lval;
			else
				*va_arg(px->ap, ptrdiff_t *) = (ptrdiff_t)lval;
			break;

		case L'z':
			if (pans != 0)
				*(ptrdiff_t *)pans = (ptrdiff_t)lval;
			else
				*va_arg(px->ap, ptrdiff_t *) = (ptrdiff_t)lval;
			break;

		case L'h':
			if (pans != 0)
				*(short *)pans = (short)lval;
			else
				*va_arg(px->ap, short *) = (short)lval;
			break;

		case L'l':
			if (pans != 0)
				*(long *)pans = (long)lval;
			else
				*va_arg(px->ap, long *) = (long)lval;
			break;

		default:
			if (pans != 0)
				*(int *)pans = (int)lval;
			else
				*va_arg(px->ap, int *) = (int)lval;
			}
		}
	else
		{	/* deliver an unsigned integer */
Example #22
0
_IO_size_t
_IO_getwline_info (_IO_FILE *fp, wchar_t *buf, _IO_size_t n, wint_t delim,
		   int extract_delim, wint_t *eof)
{
  wchar_t *ptr = buf;
  if (eof != NULL)
    *eof = 0;
  if (__builtin_expect (fp->_mode, 1) == 0)
    _IO_fwide (fp, 1);
  while (n != 0)
    {
      _IO_ssize_t len = (fp->_wide_data->_IO_read_end
			 - fp->_wide_data->_IO_read_ptr);
      if (len <= 0)
	{
	  wint_t wc = __wuflow (fp);
	  if (wc == WEOF)
	    {
	      if (eof)
		*eof = wc;
	      break;
	    }
	  if (wc == delim)
	    {
 	      if (extract_delim > 0)
		*ptr++ = wc;
	      else if (extract_delim < 0)
		_IO_sputbackc (fp, wc);
	      if (extract_delim > 0)
		++len;
	      return ptr - buf;
	    }
	  *ptr++ = wc;
	  n--;
	}
      else
	{
	  wchar_t *t;
	  if ((_IO_size_t) len >= n)
	    len = n;
	  t = wmemchr ((void *) fp->_wide_data->_IO_read_ptr, delim, len);
	  if (t != NULL)
	    {
	      _IO_size_t old_len = ptr - buf;
	      len = t - fp->_wide_data->_IO_read_ptr;
	      if (extract_delim >= 0)
		{
		  ++t;
		  if (extract_delim > 0)
		    ++len;
		}
	      wmemcpy ((void *) ptr, (void *) fp->_wide_data->_IO_read_ptr,
		       len);
	      fp->_wide_data->_IO_read_ptr = t;
	      return old_len + len;
	    }
	  wmemcpy ((void *) ptr, (void *) fp->_wide_data->_IO_read_ptr, len);
	  fp->_wide_data->_IO_read_ptr += len;
	  ptr += len;
	  n -= len;
	}
    }
  return ptr - buf;
}
Example #23
0
wchar_t *wstring_fmt_real(wchar_t *wstring, const wchar_t *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	try wstring = wstring_fmt_real_v(wstring, fmt, args);
	va_end(args);
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_fmt_real_v(wchar_t *wstring, const wchar_t *fmt, va_list args) {
	if (!fmt) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	scope {
		wchar_t *new_wstring = array_new(wchar_t, 1, ARRAY_NULL_TERMINATED);
		int wanted_size;
		va_list args_copy;
		try {
			for (va_copy(args_copy, args);
					(wanted_size = vswprintf(new_wstring, array_length(new_wstring) + sizeof(wchar_t), fmt, args_copy)) > (ssize_t)array_length(new_wstring);
					va_copy(args_copy, args)) {
				va_end(args_copy);
				array_resize(new_wstring, wanted_size);
			};
			va_end(args_copy);
			if (wanted_size < 0) throw_errno();
			array_resize(new_wstring, wanted_size);
		};
		catch throw_proxy();
		wstring_set(wstring, new_wstring);
	};
	return wstring;
};

wchar_t *wstring_cut_real(wchar_t *wstring, size_t pos, size_t len) {
	try {
		if (pos + len < pos) throw(exception_type_integer_overflow, ERANGE, integer_overflow, NULL);
		if (pos + len >= array_length(wstring)) {
			throw(exception_type_index_out_of_bound, EINVAL, index_out_of_bound, NULL);
		};
		wmemmove(&wstring[pos], &wstring[pos + len], array_length(wstring) - len - pos);
		array_resize(wstring, array_length(wstring) - len);
	};
	catch throw_proxy();
	return wstring;
};

size_t wstring_length(wchar_t *wstring) {
	size_t ret = 0;
	try {
		ret = array_length(wstring);
	};
	catch throw_proxy();
	return ret;
};

wchar_t *wstring_new() {
	wchar_t *wstring = NULL;
	try {
		wstring = array_new(wchar_t, 0, ARRAY_NULL_TERMINATED);
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_push_real(wchar_t *wstring, wchar_t push) {
	if (!push) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	try {
		array_push(wstring, push);
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_clean_real(wchar_t *wstring) {
	try {
		array_resize(wstring, 0);
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_set_real(wchar_t *wstring, const wchar_t *set) {
	if (!set) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	try {
		array_resize(wstring, wcslen(set));
	};
	catch throw_proxy();
	wcscpy(wstring, set);
	return wstring;
};

wchar_t *wstring_cat_real(wchar_t *wstring, const wchar_t *cat) {
	if (!cat) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	try {
		array_add(wstring, cat, wcslen(cat));
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_ncat_real(wchar_t *wstring, const wchar_t *cat, size_t cat_len) {
	if (!cat) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	wchar_t *end_str;
	if ((end_str = wmemchr(cat, L'\0', cat_len))) {
		cat_len = end_str - cat;
	};
	try {
		array_add(wstring, cat, cat_len);
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_new_fmt(const wchar_t *fmt, ...) {
	va_list va;
	wchar_t *ret = NULL;
	va_start(va, fmt);
	try {
		ret = wstring_new_fmt_v(fmt, va);
	};
	va_end(va);
	catch throw_proxy();
	return ret;
};

wchar_t *wstring_set_from_string_real(wchar_t *wstring, const char *string) {
	if (!string) throw(exception_type_null, EINVAL, second_arg_is_null, NULL);
	try {
		size_t need_size = mbstowcs(NULL, string, 0);
		array_resize(wstring, need_size);
		mbstowcs(wstring, string, need_size);
	};
	catch throw_proxy();
	return wstring;
};

wchar_t *wstring_new_set(const wchar_t *set) {
	wchar_t *string = NULL;
	try {
		string = array_new(wchar_t, set ? wcslen(set) : 0, ARRAY_NULL_TERMINATED);
		if (set) wcscpy(string, set);
	};
	catch throw_proxy();
	return string;
};

wchar_t *wstring_new_fmt_v(const wchar_t *fmt, va_list va) {
	return wstring_fmt_real_v(wstring_new(), fmt, va);
};
DWRITE_TEXT_METRICS TextFormatD2D::GetMetrics(
	const WCHAR* str, UINT strLen, bool gdiEmulation, float maxWidth)
{
	// GDI+ compatibility: If the last character is a newline, GDI+ measurements seem to ignore it.
	bool strippedLastNewLine = false;
	if (strLen > 2 && str[strLen - 1] == L'\n')
	{
		strippedLastNewLine = true;
		--strLen;

		if (str[strLen - 1] == L'\r')
		{
			--strLen;
		}
	}

	DWRITE_TEXT_METRICS metrics = {0};
	Microsoft::WRL::ComPtr<IDWriteTextLayout> textLayout;
	HRESULT hr = CanvasD2D::c_DWFactory->CreateTextLayout(
		str,
		strLen,
		m_TextFormat.Get(),
		maxWidth,
		10000,
		textLayout.GetAddressOf());
	if (SUCCEEDED(hr))
	{
		const float xOffset = m_TextFormat->GetFontSize() / 6.0f;
		if (gdiEmulation)
		{
			Microsoft::WRL::ComPtr<IDWriteTextLayout1> textLayout1;
			textLayout.As(&textLayout1);

			const float emOffset = xOffset / 24.0f;
			const DWRITE_TEXT_RANGE range = {0, strLen};
			textLayout1->SetCharacterSpacing(emOffset, emOffset, 0.0f, range);
		}

		textLayout->GetMetrics(&metrics);
		if (metrics.width > 0.0f)
		{
			if (gdiEmulation)
			{
				metrics.width += xOffset * 2;
				metrics.height += m_ExtraHeight;

				// GDI+ compatibility: If the string contains a newline (even if it is the
				// stripped last character), GDI+ adds the line gap to the overall height.
				if (strippedLastNewLine || wmemchr(str, L'\n', strLen) != nullptr)
				{
					metrics.height += m_LineGap;
				}
			}
			else
			{
				// GDI+ compatibility: With accurate metrics, the line gap needs to be subtracted
				// from the overall height if the string does not contain newlines.
				if (!strippedLastNewLine && wmemchr(str, L'\n', strLen) == nullptr)
				{
					metrics.height -= m_LineGap;
				}
			}
		}
		else
		{
			// GDI+ compatibility: Get rid of the height that DirectWrite assigns to zero-width
			// strings.
			metrics.height = 0.0f;
		}
	}

	return metrics;
}
Example #25
0
size_t wcsnlen(const wchar_t *s, size_t n)
{
	const wchar_t *z = wmemchr(s, 0, n);
	if (z) n = z-s;
	return n;
}
Example #26
0
/**
 * `wchar_t` version of `strnlen`.
 * 
 * @param   str     The string.
 * @param   maxlen  The number of bytes to inspect, at most.
 * @return          The number of `wchar_t`:s before the
 *                  first NUL character. `maxlen` if no
 *                  NUL character was found.
 * 
 * @since  Always.
 */
size_t wcsnlen(const wchar_t* str, size_t maxlen)
{
  const wchar_t* end = wmemchr(str, 0, maxlen);
  return end == NULL ? maxlen : (size_t)(end - str);
}
Example #27
0
gcc_pure gcc_nonnull_all
static inline wchar_t *
StringFind(wchar_t *haystack, wchar_t needle, size_t size)
{
  return wmemchr(haystack, needle, size);
}
Example #28
0
BOOL ClipboardPaste(void)
{
	HGLOBAL  hMem = 0;
	LPSTR	 lpMem;
	UINT	 uFormat = CharSet == CS_OEM ? CF_OEMTEXT : CF_TEXT;
	LONG	 lSize;
	MODEENUM SaveMode;
	BOOL	 FreeConversionMemory = FALSE;

	if (IsViewOnly()) return(FALSE);

	/*prepare resources...*/
	if (!OpenClipboard(hwndMain)) {
		ErrorBox(MB_ICONEXCLAMATION, 302);
		return (FALSE);
	}

	/*first check for binary data containing null bytes...*/
	if (UtfEncoding != 16 && (hMem = GetClipboardData(uFormat)) != 0) {
		lSize = GlobalSize(hMem);
		if ((lpMem = GlobalLock(hMem)) != NULL) {
			LPSTR lp;
			LONG  lRemain;

			lp = _fmemchr(lpMem, '\0', (size_t)lSize);
			if (lp != NULL && (lp-lpMem+sizeof(BinaryPart)) <= (size_t)lSize
						   && lp[1]==BinaryFormat[0]
						   && _fmemchr(lp+1, '\0', lSize-(lp+1-lpMem)) != NULL
						   && _fmemcmp(lp+1, BinaryFormat, 10) == 0) {
				/*insert first part of null containing binary data...*/
				SaveMode = Mode;
				if (Mode != InsertMode && Mode != ReplaceMode) {
					StartUndoSequence();
					Mode = InsertMode;
				}
				if (SelectCount) DeleteSelected(17);
				else EnterDeleteForUndo(&CurrPos, 0, 1); /*force new undo elem*/
				Mode = SaveMode;
				HideEditCaret();
				if (*lpMem) InsertBuffer(lpMem, (UINT)(lp-lpMem), 0);
				lRemain = strtoul(lp+11, &lp, 10);
				if (*lp != ':') lSize = 0;
				else {
					if (lSize >= (lp - lpMem) + lRemain) lSize = lRemain;
					else lSize = 0;
					lpMem = lp + 1;
				}
				if (lSize) InsertBuffer(lpMem, (UINT)lSize, 1);
				GetXPos(&CurrCol);
				ShowEditCaret();

				/*clean up...*/
				GlobalUnlock(hMem);
				CloseClipboard();
				return (TRUE);
			}
			GlobalUnlock(hMem);
			hMem = 0;
		}
	}

	/*then, if running on Windows NT, try to get wide chars...*/
	if (!(GetVersion() & 0x80000000U) && CharSet != CS_EBCDIC) {
		UINT Cp;

		if (UtfEncoding == 8)
			 Cp = CP_UTF8;
		else if (CharSet == CS_ANSI)
			 Cp = AnsiCodePage;
		else Cp = OemCodePage;
		if (Cp) {
			HGLOBAL	hWideCharMem = GetClipboardData(CF_UNICODETEXT);
			WCHAR	*lpWideCharMem;

			if (hWideCharMem) {
				lSize		  = GlobalSize(hWideCharMem);
				lpWideCharMem = GlobalLock(hWideCharMem);
				if (lpWideCharMem != NULL) {
					INT	   nSizeRequired;
					PWCHAR wp;

					lSize >>= 1;
					wp = wmemchr(lpWideCharMem, '\0', lSize);
					if (wp != NULL) lSize = wp - lpWideCharMem;
					if (UtfEncoding == 16) {
						lSize <<= 1;
						if (UtfLsbFirst) {
							hMem  = hWideCharMem;
							lpMem = (LPSTR)lpWideCharMem;
						} else {
							hMem  = GlobalAlloc(GMEM_MOVEABLE, lSize);
							if (hMem) {
								lpMem = GlobalLock(hMem);
								if (lpMem != NULL) {
									INT i = 0;

									while ((i += 2) <= lSize) {
										lpMem[i-2] = *lpWideCharMem >> 8;
										lpMem[i-1] = *lpWideCharMem++ & 255;
									}
									FreeConversionMemory = TRUE;
								} else {
									GlobalFree(hMem);
									hMem = 0;
								}
							}
						}
					} else {
Example #29
0
BOOL IsWordDiv(int c)
{
	return (wmemchr(Opt.WordDiv, c, Opt.WordDivLen)!=NULL);
}
Example #30
0
 static const char_type* 
 find(const char_type* __s, size_t __n, const char_type& __a)
 { return (char_type*)wmemchr((wchar_t*)__s, __a, __n); }