本文整理汇总了C++中UnicodeString::getTerminatedBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ UnicodeString::getTerminatedBuffer方法的具体用法?C++ UnicodeString::getTerminatedBuffer怎么用?C++ UnicodeString::getTerminatedBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnicodeString
的用法示例。
在下文中一共展示了UnicodeString::getTerminatedBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSearcherFullField
void SearcherTest::testSearcherFullField(void)
{
UnicodeString strQuery;
const UChar *uStr;
// Populate the database
Entry e;
EntrySet entrySet;
UnicodeString word = "A full field";
// Add one word and entry
e.Set(1, 1, 1);
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Search the database for a field only
// This will use Lexer::ReadFullField as the field is in <quotes>
strQuery = "<A full field>";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
// Add a new entry to a word
e.Set(2, 2, 2);
word = "test";
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Search the database for a field or a word
strQuery = "<A full field> test";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
}
示例2: testSearcherRange
void SearcherTest::testSearcherRange(void)
{
UnicodeString strQuery;
const UChar *uStr;
// Populate the database
Entry e;
EntrySet entrySet;
UnicodeString word;
// Add one word and entry
e.Set(1, 1, 1);
word = "a";
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Add a new word and entry
e.Set(2, 2, 2);
word = "b";
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Add a new word and entry
e.Set(3, 3, 3);
word = "c";
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Search the database
strQuery = "[a TO c]";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT_MESSAGE("[a TO c]", entrySet == *(mSearcher->GetEntrySet()));
// Add a new word and entry
e.Set(4, 4, 4);
word = "d";
mDbNdx->AddWordEntry(word, e);
// Search the database (without "TO")
strQuery = "[a c]";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT_MESSAGE("[a c]", entrySet == *(mSearcher->GetEntrySet()));
// Keep only the "b" in the result set
entrySet.clear();
e.Set(2, 2, 2);
entrySet.insert(e);
// Search the database
strQuery = "{a TO c}";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT_MESSAGE("{a TO c}", entrySet == *(mSearcher->GetEntrySet()));
}
示例3: VariableFound
/**
* Override this method to perform any custom logic when a variable assignment is found. Note that the same
* variable may be assigned different values at different times within the same function.
* The symbol will be constructed in the following way:
*
* Example assignment: $name = $this->getName()->toString();
*
* Variable: The variable's ChainList will contain the variable's name in index 0: "$name"
* ChainList: This is a list of properties / methods
* that were successively invoked.
* In this example, the expression chain list will have 3 items in
* the chain list "$this" "->getName()" and "->toString()".
*
* The variable itself may contain an array key in it; like so: $person['name'] = $this->getName()->toString();
* In this case, Variable ChainList will contain 1 item: "$name" and the Variable Array Key will contain "name"
*
*
* @param const UnicodeString& namespace the fully qualified namespace of the containing class / function.
* @param const UnicodeString& className class where the variable was found. may be empty is variable is scoped
* inside a function or is global.
* @param const UnicodeString& methodName function/method name where the variable was found. may be empty if
* variable is globally scoped.
* @param const VariableClass& variable the name of the variable that was found, along with any array keys that were used
* in the left hand of the assignment.
* @param const ExpressionClass& expression the expression assigned to the variable
* @param const UnicodeString& comment PHPDoc attached to the variable
*
* @see pelet::VariableClass
*/
virtual void VariableFound(const UnicodeString& namespaceName, const UnicodeString& className, const UnicodeString& methodName,
const pelet::VariableClass& variable, pelet::ExpressionClass* expression, const UnicodeString& comment) {
UFILE* ufout = u_finit(stdout, NULL, NULL);
UnicodeString scope;
if (className.isEmpty() && methodName.isEmpty()) {
scope = UNICODE_STRING_SIMPLE("<global>");
}
else if (className.isEmpty() && !methodName.isEmpty()) {
scope = methodName;
}
else {
scope = className + UNICODE_STRING_SIMPLE("::") + methodName;
}
UnicodeString type;
if (variable.IsPhpDocVariable && !variable.PhpDocType.isEmpty()) {
type += UNICODE_STRING_SIMPLE("Variable is decorated with a PHPDoc comment: ");
type += variable.PhpDocType;
}
else if (pelet::ExpressionClass::ARRAY == expression->ExpressionType) {
type = UNICODE_STRING_SIMPLE("Variable is an array");
}
else if (pelet::ExpressionClass::SCALAR == expression->ExpressionType) {
type = UNICODE_STRING_SIMPLE("Variable is a primitive");
}
else if (pelet::ExpressionClass::VARIABLE == expression->ExpressionType) {
type = UNICODE_STRING_SIMPLE("Variable is a variable expression. ");
type += UNICODE_STRING_SIMPLE("Chain list is: ");
pelet::VariableClass* srcVariable = (pelet::VariableClass*) expression;
for (size_t i = 0; i < srcVariable->ChainList.size(); ++i) {
if (srcVariable->ChainList[i].IsStatic && i > 0) {
type += UNICODE_STRING_SIMPLE("::");
}
else if (i > 0) {
type += UNICODE_STRING_SIMPLE("->");
}
type += srcVariable->ChainList[i].Name;
if (srcVariable->ChainList[i].IsFunction) {
type += UNICODE_STRING_SIMPLE("()");
}
if (i < (srcVariable->ChainList.size() - 1)) {
type += UNICODE_STRING_SIMPLE(", ");
}
}
}
else if (pelet::ExpressionClass::UNKNOWN == expression->ExpressionType) {
type = UNICODE_STRING_SIMPLE("Variable is of unknown type.");
}
u_fprintf(ufout, "Variable Found: %.*S in scope %S. %S\n",
variable.ChainList[0].Name.length(), variable.ChainList[0].Name.getBuffer(),
scope.getTerminatedBuffer(),
type.getTerminatedBuffer());
}
示例4: testSearcherAnd
void SearcherTest::testSearcherAnd(void)
{
UnicodeString strQuery;
const UChar *uStr;
// Populate the database
Entry e;
EntrySet entrySet;
UnicodeString word = "test1";
// Add one word and entry
e.Set(1, 1, 1);
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Add a new word and entry
e.Set(1, 1, 2);
entrySet.insert(e);
word = "test2";
mDbNdx->AddWordEntry(word, e);
// Add a new entry to this word
e.Set(2, 2, 2);
mDbNdx->AddWordEntry(word, e);
// Search the database
strQuery = "test1 AND test2";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
// Add a new word and entry
e.Set(1, 1, 3);
entrySet.insert(e);
word = "test3";
mDbNdx->AddWordEntry(word, e);
// Add a new entry to this word
e.Set(2, 2, 2);
mDbNdx->AddWordEntry(word, e);
// Add a new entry to this word
e.Set(3, 3, 3);
mDbNdx->AddWordEntry(word, e);
// Search the database
strQuery = "test1 AND test2 AND test3";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
}
示例5: getBestPatternExample
static void getBestPatternExample() {
u_printf("========================================================================\n");
u_printf(" getBestPatternExample()\n");
u_printf("\n");
u_printf(" Use DateTimePatternGenerator to create customized date/time pattern:\n");
u_printf(" yQQQQ,yMMMM, MMMMd, hhmm, jjmm per locale\n");
u_printf("========================================================================\n");
//! [getBestPatternExample]
UnicodeString skeletons [] = {
UnicodeString("yQQQQ"), // year + full name of quarter, i.e., 4th quarter 1999
UnicodeString("yMMMM"), // year + full name of month, i.e., October 1999
UnicodeString("MMMMd"), // full name of month + day of the month, i.e., October 25
UnicodeString("hhmm"), // 12-hour-cycle format, i.e., 1:32 PM
UnicodeString("jjmm"), // preferred hour format for the given locale, i.e., 24-hour-cycle format for fr_FR
0,
};
Locale locales[] = {
Locale ("en_US"),
Locale ("fr_FR"),
Locale ("zh_CN"),
};
const char* filename = "sample.txt";
/* open a UTF-8 file for writing */
UFILE* f = u_fopen(filename, "w", NULL,"UTF-8");
UnicodeString dateReturned;
UErrorCode status =U_ZERO_ERROR;
Calendar *cal = Calendar::createInstance(status);
cal->set (1999,9,13,23,58,59);
UDate date = cal->getTime(status);
u_fprintf(f, "%-20S%-20S%-20S%-20S\n", UnicodeString("Skeleton").getTerminatedBuffer(),UnicodeString("en_US").getTerminatedBuffer(),UnicodeString("fr_FR").getTerminatedBuffer(),UnicodeString("zh_CN").getTerminatedBuffer());
for (int i=0;skeletons[i]!=NULL;i++) {
u_fprintf(f, "%-20S",skeletons[i].getTerminatedBuffer());
for (int j=0;j<sizeof(locales)/sizeof(locales[0]);j++) {
// create a DateTimePatternGenerator instance for given locale
DateTimePatternGenerator *dtfg= DateTimePatternGenerator::createInstance(locales[j],status);
// use getBestPattern method to get the best pattern for the given skeleton
UnicodeString pattern = dtfg->getBestPattern(skeletons[i],status);
// Constructs a SimpleDateFormat with the best pattern generated above and the given locale
SimpleDateFormat *sdf = new SimpleDateFormat(pattern,locales[j],status);
dateReturned.remove();
// Get the format of the given date
sdf->format(date,dateReturned,status);
/* write Unicode string to file */
u_fprintf(f, "%-20S", dateReturned.getTerminatedBuffer());
delete dtfg;
delete sdf;
}
u_fprintf(f,"\n");
}
/* close the file resource */
u_fclose(f);
delete cal;
//! [getBestPatternExample]
}
示例6: testSearcherPrefix
void SearcherTest::testSearcherPrefix(void)
{
bool isLogError;
UnicodeString strQuery;
const UChar *uStr;
// Populate the database
Entry e;
EntrySet entrySet;
UnicodeString word = "test";
// Add one word and entry
e.Set(1, 1, 1);
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Add a new entry to this word
e.Set(2, 2, 2);
entrySet.insert(e);
mDbNdx->AddWordEntry(word, e);
// Search the database
strQuery = cStrField;
strQuery += ":test";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
// Search with a wrong prefix
isLogError = gLog.isInLogLevel(eTypLogError);
gLog.removeLogLevel(eTypLogError); // Remove errors
entrySet.clear();
strQuery = "wrong_prefix:test";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
strQuery = "wrong_prefix:test*";
uStr = strQuery.getTerminatedBuffer();
mSearcher->SetQuery(cStrField, uStr);
mSearcher->Compute();
CPPUNIT_ASSERT(entrySet == *(mSearcher->GetEntrySet()));
if (isLogError)
gLog.addLogLevel(eTypLogError); // Show errors
}
示例7: t_ucharcharacteriterator_init
static int t_ucharcharacteriterator_init(t_ucharcharacteriterator *self,
PyObject *args, PyObject *kwds)
{
UnicodeString *u;
int len, start, end, pos;
switch (PyTuple_Size(args)) {
case 2:
if (!parseArgs(args, "Wi", &u, &self->text, &len))
{
self->object = new UCharCharacterIterator(u->getTerminatedBuffer(), len);
self->flags = T_OWNED;
break;
}
PyErr_SetArgsError((PyObject *) self, "__init__", args);
return -1;
case 3:
if (!parseArgs(args, "Wii", &u, &self->text, &len, &pos))
{
self->object = new UCharCharacterIterator(u->getTerminatedBuffer(), len, pos);
self->flags = T_OWNED;
break;
}
PyErr_SetArgsError((PyObject *) self, "__init__", args);
return -1;
case 5:
if (!parseArgs(args, "Wiiii", &u, &self->text, &len, &start, &end, &pos))
{
self->object = new UCharCharacterIterator(u->getTerminatedBuffer(), len, start, end, pos);
self->flags = T_OWNED;
break;
}
PyErr_SetArgsError((PyObject *) self, "__init__", args);
return -1;
default:
PyErr_SetArgsError((PyObject *) self, "__init__", args);
return -1;
}
if (self->object)
return 0;
return -1;
}
示例8: replaceFieldTypesExample
static void replaceFieldTypesExample() {
// Use repalceFieldTypes API to replace zone 'zzzz' with 'vvvv'
u_printf("========================================================================\n");
u_printf(" replaceFieldTypeExample()\n");
u_printf("\n");
u_printf(" Use replaceFieldTypes API to replace zone 'zzzz' with 'vvvv'\n");
u_printf("========================================================================\n");
//! [replaceFieldTypesExample]
UFILE *out = u_finit(stdout, NULL, "UTF-8");
UErrorCode status =U_ZERO_ERROR;
UnicodeString pattern,dateReturned;
Locale locale =Locale::getFrance();
Calendar *cal = Calendar::createInstance(status);
cal->set (1999,9,13,23,58,59);
UDate date = cal->getTime(status);
TimeZone *zone = TimeZone::createTimeZone(UnicodeString("Europe/Paris"));
DateTimePatternGenerator *dtfg = DateTimePatternGenerator::createInstance(locale,status);
SimpleDateFormat *sdf = new SimpleDateFormat("EEEE d MMMM y HH:mm:ss zzzz",locale,status);
sdf->setTimeZone(*zone);
pattern = sdf->toPattern(pattern);
u_fprintf(out, "%S\n", UnicodeString("Pattern before replacement:").getTerminatedBuffer());
u_fprintf(out, "%S\n", pattern.getTerminatedBuffer());
dateReturned.remove();
dateReturned = sdf->format(date, dateReturned, status);
u_fprintf(out, "%S\n", UnicodeString("Date/Time format in fr_FR:").getTerminatedBuffer());
u_fprintf(out, "%S\n", dateReturned.getTerminatedBuffer());
// Replace zone "zzzz" in the pattern with "vvvv"
UnicodeString newPattern = dtfg->replaceFieldTypes(pattern, "vvvv", status);
// Apply the new pattern
sdf->applyPattern(newPattern);
dateReturned.remove();
dateReturned = sdf->format(date, dateReturned, status);
u_fprintf(out, "%S\n", UnicodeString("Pattern after replacement:").getTerminatedBuffer());
u_fprintf(out, "%S\n", newPattern.getTerminatedBuffer());
u_fprintf(out, "%S\n", UnicodeString("Date/Time format in fr_FR:").getTerminatedBuffer());
u_fprintf(out, "%S\n", dateReturned.getTerminatedBuffer());
delete sdf;
delete dtfg;
delete zone;
delete cal;
u_fclose(out);
//! [replaceFieldTypesExample]
/* output of the sample code:
*************************************************************************************************
Pattern before replacement:
EEEE d MMMM y HH:mm:ss zzzz
Date/Time format in fr_FR:
jeudi 14 octobre 1999 05:58:59 heure avancée d’Europe centrale
Pattern after replacement:
EEEE d MMMM y HH:mm:ss vvvv
Date/Time format in fr_FR:
jeudi 14 octobre 1999 05:58:59 heure de l’Europe centrale
*************************************************************************************************/
}
示例9: EnumCalendarArray
/*
Function:
EnumCalendarArray
Enumerates an array of strings and invokes the callback for each value.
*/
bool EnumCalendarArray(const UnicodeString* srcArray, int32_t srcArrayCount, EnumCalendarInfoCallback callback, const void* context)
{
for (int i = 0; i < srcArrayCount; i++)
{
UnicodeString src = srcArray[i];
callback(src.getTerminatedBuffer(), context);
}
return true;
}
示例10: printStringInHexadecimal
void kiwix::printStringInHexadecimal(UnicodeString s) {
std::cout << std::showbase << std::hex;
for (int i=0; i<s.length(); i++) {
char c = (char)((s.getTerminatedBuffer())[i]);
if (c & 0x80)
std::cout << (c & 0xffff) << " ";
else
std::cout << c << " ";
}
std::cout << std::endl;
}
示例11: ret
UnicodeString StringConverter::fromUtf8(const char* buffer, int bufferSize) {
UnicodeString tmp = UnicodeString::fromUTF8(StringPiece(buffer, bufferSize));
// a little strange, but otherwise a unicode string might be returned that is just filled with 0x00, but still
// has length > 0 and is != "" etc
UnicodeString ret(tmp.getTerminatedBuffer());
if (ret.isBogus()) {
ret = UnicodeString("##FLUOERROR"); // set error string
LOG_WARN << "Unable to convert from utf-8 string" << std::endl;
}
return ret;
}
示例12: GetDisplayName
const char * GetDisplayName(char * strID)
#endif
{
UnicodeString strDisplayName;
Transliterator::getDisplayName(strID, strDisplayName);
#ifdef _MSC_VER
return ::SysAllocString(strDisplayName.getTerminatedBuffer());
#else
char * name = UniStr_to_CharStar(strDisplayName);
return name;
#endif
}
示例13: PyErr_SetArgsError
static PyObject *t_ucharcharacteriterator_setText(t_ucharcharacteriterator *self, PyObject *args)
{
UnicodeString *u;
int32_t length;
if (!parseArgs(args, "Wi", &u, &self->text, &length))
{
self->object->setText(u->getTerminatedBuffer(), length); /* ref'd */
Py_RETURN_NONE;
}
return PyErr_SetArgsError((PyObject *) self, "setText", args);
}
示例14: GetDateSeparator
VString XLinuxIntlMgr::GetDateSeparator() const
{
VString dateSeparator;
icu::DateFormat* dateFmt=icu::DateFormat::createDateInstance(icu::DateFormat::SHORT, fLocale);
xbox_assert(dateFmt!=NULL);
icu::SimpleDateFormat* simpleDateFmt=reinterpret_cast<icu::SimpleDateFormat*>(dateFmt);
xbox_assert(simpleDateFmt!=NULL);
if(simpleDateFmt!=NULL)
{
UErrorCode err=U_ZERO_ERROR;
UnicodeString tmpPattern;
simpleDateFmt->toLocalizedPattern(tmpPattern, err);
xbox_assert(err==U_ZERO_ERROR);
VString datePattern(tmpPattern.getTerminatedBuffer());
bool isQuoted=false;
for(int i=0 ; i<datePattern.GetLength() ; i++)
{
UniChar c=datePattern[i];
if(c=='\'')
isQuoted=!isQuoted;
if(isQuoted)
continue;
//ICU works with patterns ("M/d/yy" for ex.) and doesn't have a notion of date separator.
//As a work around, we try to get a localized date pattern and pick the first char that looks like a separator.
if(!(c>='A' && c<='Z') && !(c>='a' && c<='z'))
{
dateSeparator.AppendUniChar(c);
break;
}
}
}
if(dateFmt!=NULL)
delete dateFmt;
xbox_assert(!dateSeparator.IsEmpty());
if(dateSeparator.IsEmpty())
return VString("/");
return dateSeparator;
}
示例15: sizeof
/* static */ void
ICUUtils::ToMozString(UnicodeString& aICUString, nsAString& aMozString)
{
// Both ICU's UnicodeString and Mozilla's nsAString use UTF-16, so we can
// cast here.
static_assert(sizeof(UChar) == 2 && sizeof(nsAString::char_type) == 2,
"Unexpected character size - the following cast is unsafe");
const nsAString::char_type* buf =
(const nsAString::char_type*)aICUString.getTerminatedBuffer();
aMozString.Assign(buf);
NS_ASSERTION(aMozString.Length() == (uint32_t)aICUString.length(),
"Conversion failed");
}