本文整理汇总了C++中BreakIterator类的典型用法代码示例。如果您正苦于以下问题:C++ BreakIterator类的具体用法?C++ BreakIterator怎么用?C++ BreakIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BreakIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ubrk_openRules
//----------------------------------------------------------------------------------------
//
// ubrk_openRules open a break iterator from a set of break rules.
// Invokes the rule builder.
//
//----------------------------------------------------------------------------------------
U_CAPI UBreakIterator* U_EXPORT2
ubrk_openRules( const UChar *rules,
int32_t rulesLength,
const UChar *text,
int32_t textLength,
UParseError *parseErr,
UErrorCode *status) {
if (status == NULL || U_FAILURE(*status)){
return 0;
}
BreakIterator *result = 0;
UnicodeString ruleString(rules, rulesLength);
result = RBBIRuleBuilder::createRuleBasedBreakIterator(ruleString, *parseErr, *status);
if(U_FAILURE(*status)) {
return 0;
}
if (text != NULL) {
UCharCharacterIterator *iter = 0;
iter = new UCharCharacterIterator(text, textLength);
if(iter == 0) {
*status = U_MEMORY_ALLOCATION_ERROR;
delete result;
return 0;
}
result->adoptText(iter);
}
return (UBreakIterator *)result;
}
示例2: ubrk_refreshUText
void ubrk_refreshUText(UBreakIterator *bi,
UText *text,
UErrorCode *status)
{
BreakIterator *bii = reinterpret_cast<BreakIterator *>(bi);
bii->refreshInputText(text, *status);
}
示例3: next
/*
* Return the next break, counting words and spaces.
*/
int32_t SpaceBreakIterator::next()
{
if (fDone) {
return BreakIterator::DONE;
}
int32_t nextBreak;
do {
nextBreak = fBreakIter->next();
if (nextBreak == BreakIterator::DONE) {
fDone = TRUE;
return BreakIterator::DONE;
}
}
while(nextBreak > 0 && fComplexContext.contains(fText[nextBreak-1])
&& fComplexContext.contains(fText[nextBreak]));
int32_t result = nextBreak - fSpaceCount;
if (nextBreak < fTextCount) {
if (fText[nextBreak] == 0x0020 /*Unicode::isSpaceChar(fText[nextBreak])*/) {
fSpaceCount += fBreakIter->next() - nextBreak;
}
}
fWordCount += 1;
return result;
}
示例4: u_strToTitle
U_NAMESPACE_USE
/* functions available in the common library (for unistr_case.cpp) */
/* public API functions */
U_CAPI int32_t U_EXPORT2
u_strToTitle(UChar *dest, int32_t destCapacity,
const UChar *src, int32_t srcLength,
UBreakIterator *titleIter,
const char *locale,
UErrorCode *pErrorCode) {
LocalPointer<BreakIterator> ownedIter;
BreakIterator *iter;
if(titleIter!=NULL) {
iter=reinterpret_cast<BreakIterator *>(titleIter);
} else {
iter=BreakIterator::createWordInstance(Locale(locale), *pErrorCode);
ownedIter.adoptInstead(iter);
}
if(U_FAILURE(*pErrorCode)) {
return 0;
}
UnicodeString s(srcLength<0, src, srcLength);
iter->setText(s);
return ustrcase_mapWithOverlap(
ustrcase_getCaseLocale(locale), 0, iter,
dest, destCapacity,
src, srcLength,
ustrcase_internalToTitle, *pErrorCode);
}
示例5: ubrk_setUText
U_DRAFT void U_EXPORT2
ubrk_setUText(UBreakIterator *bi,
UText *text,
UErrorCode *status)
{
BreakIterator *brit = (BreakIterator *)bi;
brit->setText(text, *status);
}
示例6: _breakiterator_rewind
static void _breakiterator_rewind(zend_object_iterator *iter)
{
BreakIterator *biter = _breakiter_prolog(iter);
zoi_with_current *zoi_iter = (zoi_with_current*)iter;
int32_t pos = biter->first();
ZVAL_LONG(&zoi_iter->current, (zend_long)pos);
}
示例7: ubrk_open
//----------------------------------------------------------------------------------------
//
// ubrk_open Create a canned type of break iterator based on type (word, line, etc.)
// and locale.
//
//----------------------------------------------------------------------------------------
U_CAPI UBreakIterator* U_EXPORT2
ubrk_open(UBreakIteratorType type,
const char *locale,
const UChar *text,
int32_t textLength,
UErrorCode *status)
{
if(U_FAILURE(*status)) return 0;
BreakIterator *result = 0;
switch(type) {
case UBRK_CHARACTER:
result = BreakIterator::createCharacterInstance(Locale(locale), *status);
break;
case UBRK_WORD:
result = BreakIterator::createWordInstance(Locale(locale), *status);
break;
case UBRK_LINE:
result = BreakIterator::createLineInstance(Locale(locale), *status);
break;
case UBRK_SENTENCE:
result = BreakIterator::createSentenceInstance(Locale(locale), *status);
break;
case UBRK_TITLE:
result = BreakIterator::createTitleInstance(Locale(locale), *status);
break;
}
// check for allocation error
if (U_FAILURE(*status)) {
return 0;
}
if(result == 0) {
*status = U_MEMORY_ALLOCATION_ERROR;
return 0;
}
if (text != NULL) {
UCharCharacterIterator *iter = 0;
iter = new UCharCharacterIterator(text, textLength);
if(iter == 0) {
*status = U_MEMORY_ALLOCATION_ERROR;
delete result;
return 0;
}
result->adoptText(iter);
}
return (UBreakIterator*)result;
}
示例8: thai
/*
* This method does the acutal break comparison and reports the results.
* It uses a SpaceBreakIterator to iterate over the text with spaces,
* and a word instance of a Thai BreakIterator to iterate over the text
* without spaces.
*/
UBool ThaiWordbreakTest::compareWordBreaks(const UChar *spaces, int32_t spaceCount,
const UChar *noSpaces, int32_t noSpaceCount)
{
UBool result = TRUE;
Locale thai("th");
UCharCharacterIterator *noSpaceIter = new UCharCharacterIterator(noSpaces, noSpaceCount);
UErrorCode status = U_ZERO_ERROR;
BreakIterator *breakIter = BreakIterator::createWordInstance(thai, status);
breakIter->adoptText(noSpaceIter);
SpaceBreakIterator spaceIter(spaces, spaceCount);
int32_t nextBreak = 0;
int32_t nextSpaceBreak = 0;
int32_t iterCount = 0;
while (TRUE) {
nextSpaceBreak = spaceIter.next();
nextBreak = breakIter->next();
if (nextSpaceBreak == BreakIterator::DONE || nextBreak == BreakIterator::DONE) {
if (nextBreak != BreakIterator::DONE) {
fprintf(stderr, "break iterator didn't end.\n");
} else if (nextSpaceBreak != BreakIterator::DONE) {
fprintf(stderr, "premature break iterator end.\n");
}
break;
}
while (nextSpaceBreak != nextBreak &&
nextSpaceBreak != BreakIterator::DONE && nextBreak != BreakIterator::DONE) {
if (nextSpaceBreak < nextBreak) {
breakNotFound(nextSpaceBreak);
result = FALSE;
nextSpaceBreak = spaceIter.next();
} else if (nextSpaceBreak > nextBreak) {
foundInvalidBreak(nextBreak);
result = FALSE;
nextBreak = breakIter->next();
}
}
if (fVerbose) {
printf("%d %d\n", nextSpaceBreak, nextBreak);
}
}
fWordCount = spaceIter.getWordCount();
delete breakIter;
return result;
}
示例9: printEachBackward
/* Print each element in reverse order: */
void printEachBackward( BreakIterator& boundary)
{
int32_t end = boundary.last();
for (int32_t start = boundary.previous();
start != BreakIterator::DONE;
end = start, start = boundary.previous())
{
printTextRange( boundary, start, end );
}
}
示例10: printEachForward
/* Print each element in order: */
void printEachForward( BreakIterator& boundary)
{
int32_t start = boundary.first();
for (int32_t end = boundary.next();
end != BreakIterator::DONE;
start = end, end = boundary.next())
{
printTextRange( boundary, start, end );
}
}
示例11: main
/* Creating and using text boundaries */
int main( void )
{
puts("ICU Break Iterator Sample Program\n");
puts("C++ Break Iteration\n");
BreakIterator* boundary;
UnicodeString stringToExamine("Aaa bbb ccc. Ddd eee fff.");
printf("Examining: ");
printUnicodeString(stringToExamine);
puts("");
//print each sentence in forward and reverse order
UErrorCode status = U_ZERO_ERROR;
boundary = BreakIterator::createSentenceInstance(
Locale::getUS(), status );
if (U_FAILURE(status)) {
printf("failed to create sentence break iterator. status = %s",
u_errorName(status));
exit(1);
}
boundary->setText(stringToExamine);
puts("\n Sentence Boundaries... ");
puts("----- forward: -----------");
printEachForward(*boundary);
puts("----- backward: ----------");
printEachBackward(*boundary);
delete boundary;
//print each word in order
printf("\n Word Boundaries... \n");
boundary = BreakIterator::createWordInstance(
Locale::getUS(), status);
boundary->setText(stringToExamine);
puts("----- forward: -----------");
printEachForward(*boundary);
//print first element
puts("----- first: -------------");
printFirst(*boundary);
//print last element
puts("----- last: --------------");
printLast(*boundary);
//print word at charpos 10
puts("----- at pos 10: ---------");
printAt(*boundary, 10 );
delete boundary;
puts("\nEnd C++ Break Iteration");
// Call the C version
return c_main();
}
示例12: ubrk_close
U_CAPI void U_EXPORT2
ubrk_close(UBreakIterator *bi)
{
BreakIterator *ubi = (BreakIterator*) bi;
if (ubi) {
if (ubi->isBufferClone()) {
ubi->~BreakIterator();
*(uint32_t *)ubi = 0xdeadbeef;
} else {
delete ubi;
}
}
}
示例13: ubrk_setText
U_CAPI void U_EXPORT2
ubrk_setText(UBreakIterator* bi,
const UChar* text,
int32_t textLength,
UErrorCode* status)
{
BreakIterator *brit = (BreakIterator *)bi;
UText ut = UTEXT_INITIALIZER;
utext_openUChars(&ut, text, textLength, status);
brit->setText(&ut, *status);
// A stack allocated UText wrapping a UCHar * string
// can be dumped without explicitly closing it.
}
示例14: _breakiterator_move_forward
static void _breakiterator_move_forward(zend_object_iterator *iter)
{
BreakIterator *biter = _breakiter_prolog(iter);
zoi_with_current *zoi_iter = (zoi_with_current*)iter;
iter->funcs->invalidate_current(iter);
if (biter == NULL) {
return;
}
int32_t pos = biter->next();
if (pos != BreakIterator::DONE) {
ZVAL_LONG(&zoi_iter->current, (zend_long)pos);
} //else we've reached the end of the enum, nothing more is required
}
示例15: generateFile
/*
* Generate a text file with spaces in it from a file without.
*/
int generateFile(const UChar *chars, int32_t length) {
Locale root("");
UCharCharacterIterator *noSpaceIter = new UCharCharacterIterator(chars, length);
UErrorCode status = U_ZERO_ERROR;
UnicodeSet complexContext(UNICODE_STRING_SIMPLE("[:LineBreak=SA:]"), status);
BreakIterator *breakIter = BreakIterator::createWordInstance(root, status);
breakIter->adoptText(noSpaceIter);
char outbuf[1024];
int32_t strlength;
UChar bom = 0xFEFF;
printf("%s", u_strToUTF8(outbuf, sizeof(outbuf), &strlength, &bom, 1, &status));
int32_t prevbreak = 0;
while (U_SUCCESS(status)) {
int32_t nextbreak = breakIter->next();
if (nextbreak == BreakIterator::DONE) {
break;
}
printf("%s", u_strToUTF8(outbuf, sizeof(outbuf), &strlength, &chars[prevbreak],
nextbreak-prevbreak, &status));
if (nextbreak > 0 && complexContext.contains(chars[nextbreak-1])
&& complexContext.contains(chars[nextbreak])) {
printf(" ");
}
prevbreak = nextbreak;
}
if (U_FAILURE(status)) {
fprintf(stderr, "generate failed: %s\n", u_errorName(status));
return status;
}
else {
return 0;
}
}