예제 #1
0
  // from utf16 tans to utf8(or gbk)
  inline static std::string to_utf8(const std::u16string& in) {
    std::string out;
#ifdef MMSEG_GBK
	gbkTrans(in.begin(), in.end(), out);
#else
	unicodeToUtf8(in.begin(), in.end(), out);
#endif
	return out;
  }
예제 #2
0
void TextLabels::renderString( const std::u16string &str, vec2 *cursor, float stretch )
{
	std::u16string::const_iterator itr;
	for( itr = str.begin(); itr != str.end(); ++itr ) {
		// retrieve character code
		uint16_t id = (uint16_t)*itr;

		if( mFont->contains( id ) ) {
			// get metrics for this character to speed up measurements
			Font::Metrics m = mFont->getMetrics( id );

			// skip whitespace characters
			if( !isWhitespaceUtf16( id ) ) {
				size_t index = mVertices.size();

				Rectf bounds = mFont->getBounds( m, mFontSize );
				mVertices.push_back( vec3( *cursor + bounds.getUpperLeft(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getUpperRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerRight(), 0 ) );
				mVertices.push_back( vec3( *cursor + bounds.getLowerLeft(), 0 ) );

				bounds = mFont->getTexCoords( m );
				mTexcoords.push_back( bounds.getUpperLeft() );
				mTexcoords.push_back( bounds.getUpperRight() );
				mTexcoords.push_back( bounds.getLowerRight() );
				mTexcoords.push_back( bounds.getLowerLeft() );

				mIndices.push_back( index + 0 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 1 );
				mIndices.push_back( index + 1 ); mIndices.push_back( index + 3 ); mIndices.push_back( index + 2 );

				mOffsets.insert( mOffsets.end(), 4, mOffset );
			}

			if( id == 32 )
				cursor->x += stretch * mFont->getAdvance( m, mFontSize );
			else
				cursor->x += mFont->getAdvance( m, mFontSize );
		}
	}

	//
	mBoundsInvalid = true;
}
예제 #3
0
bool RegexStore::patternMatch(std::u16string& in_string) {
	//No pattern matches when we don't have a valid pattern
	if (not is_compiled) {
    return false;
	}

  //Check for a match
  regmatch_t pmatch;
	std::string tmp_str(in_string.begin(), in_string.end());
  int match = regexec(&exp, tmp_str.c_str(), 1, &pmatch, 0);
	//Make sure that each character was matched and that the entire input string
	//was consumed by the pattern
  if (0 == match and 0 == pmatch.rm_so and in_string.size() == pmatch.rm_eo) {
		return true;
  }
  else {
		return false;
  }
}
예제 #4
0
/*
 * Create a new regex pattern if necessary, or keep the old one if the
 * pattern has not changed
 * Returns true on success, false on failure.
 */
bool RegexStore::preparePattern(std::u16string& patt) {
	//New pattern? Clear out the existing regex_t
	if (is_compiled and this->pattern != patt) {
		//std::cerr<<"Replacing pattern "<<std::string(pattern.begin(), pattern.end())<<" with "<<std::string(patt.begin(), patt.end())
		regfree(&exp);
		is_compiled = false;
	}
	//Do we need to compile a new regex pattern?
	if (not is_compiled) {
		//Compile a new regex pattern using the ascii string representation
		std::string tmp_string(patt.begin(), patt.end());
		int err = regcomp(&exp, tmp_string.c_str(), REG_EXTENDED);
		//Return without creating an expression if this failed
		if (0 != err) {
			return false;
			//is_compiled remains false
		}
		else {
			pattern = patt;
			is_compiled = true;
		}
	}
	return true;
}
예제 #5
0
 path::path( std::u16string const & pathname ) : pathname_( pathname.begin(), pathname.end() )
 {
 }
std::string UTF16ToASCII(const std::u16string& utf16) {
#if 0
    DCHECK(isStringASCII(utf16)) << UTF16ToUTF8(utf16);
#endif
    return std::string(utf16.begin(), utf16.end());
}
예제 #7
0
std::vector<char16_t> getChar16VectorFromUTF16String(const std::u16string& utf16)
{
    return std::vector<char16_t>(utf16.begin(), utf16.end());
}