Exemplo n.º 1
0
static asstring_t *QAS_StringFromCharCodes( const CScriptArrayInterface &arr )
{
    unsigned int arr_size = arr.GetSize();
    unsigned int i;

    size_t str_len = 0;
    for( i = 0; i < arr_size; i++ ) {
        str_len += Q_WCharUtf8Length( *( (asUINT *)arr.At( i ) ) );
    }
    str_len++;

    int buf_len = str_len + 1;
    char *str = new char[buf_len];

    char *p = str;
    int char_len;
    for( i = 0; i < arr_size; i++ ) {
        char_len = Q_WCharToUtf8( *( (asUINT *)arr.At( i ) ), p, buf_len );
        p += char_len;
        buf_len -= char_len;
    }
    *p = '\0';

    asstring_t *ret = objectString_FactoryBuffer( str, str_len );

    delete[] str;

    return ret;
}
Exemplo n.º 2
0
static asstring_t *QAS_StringFromCharCode( unsigned int charCode )
{
    return objectString_FactoryBuffer( Q_WCharToUtf8Char( charCode ), Q_WCharUtf8Length( charCode ) );
}
Exemplo n.º 3
0
size_t IN_IME_GetComposition( char *str, size_t strSize, size_t *cursorPos, size_t *convStart, size_t *convLen ) {
	WCHAR compStr[IN_WINIME_COMPSTR_LENGTH + 1];
	char compAttr[IN_WINIME_COMPSTR_LENGTH + 1];
	int len, attrLen, i, cursor, attr, start = -1;
	size_t cursorutf = 0, startutf = 0, convutflen = 0, ret = 0;

	if( !strSize ) {
		str = NULL;
	}

	if( str ) {
		str[0] = '\0';
	}
	if( cursorPos ) {
		*cursorPos = 0;
	}
	if( convStart ) {
		*convStart = 0;
	}
	if( convLen ) {
		*convLen = 0;
	}

	if( !in_winime_enabled ) {
		return 0;
	}

	len = qimmGetCompositionString( in_winime_context, GCS_COMPSTR, compStr, sizeof( compStr ) ) / sizeof( WCHAR );
	if( len <= 0 ) {
		return 0;
	}

	compStr[len] = 0;
	if( str ) {
		ret = Q_WCharToUtf8String( compStr, str, strSize );
	} else {
		for( i = 0; i < len; i++ )
			ret += Q_WCharUtf8Length( compStr[i] );
	}

	if( cursorPos ) {
		cursor = LOWORD( qimmGetCompositionString( in_winime_context, GCS_CURSORPOS, NULL, 0 ) );
		for( i = 0; ( i < cursor ) && ( i < len ); i++ )
			cursorutf += Q_WCharUtf8Length( compStr[i] );
		clamp_high( cursorutf, ret );
		*cursorPos = cursorutf;
	}

	if( convStart || convLen ) {
		attrLen = qimmGetCompositionString( in_winime_context, GCS_COMPATTR, compAttr, sizeof( compAttr ) );
		if( attrLen == len ) {
			for( i = 0; i < attrLen; i++ ) {
				attr = compAttr[i];
				if( ( attr == ATTR_TARGET_CONVERTED ) || ( attr == ATTR_TARGET_NOTCONVERTED ) ) {
					if( start < 0 ) {
						start = startutf;
					}
					convutflen += Q_WCharUtf8Length( compStr[i] );
				} else {
					if( start >= 0 ) {
						break;
					}
					startutf += Q_WCharUtf8Length( compStr[i] );
				}
			}

			if( start >= 0 ) {
				if( start > ( int )ret ) {
					start = ret;
				}
				if( ( start + convutflen ) > ( int )ret ) {
					convutflen = ret - start;
				}
				if( convStart ) {
					*convStart = start;
				}
				if( convLen ) {
					*convLen = convutflen;
				}
			}
		}
	}

	return ret;
}