es_Status es_tcl_track_info(void (*appendResult)(char* res, es_ClientData data), es_ClientData data) { // balise messages es_ListEntry *next = es_tracksim_track.bmsgs; int i = 0; while(next!=NULL) { es_TriggeredBaliseMessage *bm = (es_TriggeredBaliseMessage*)next->data; snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"{b %d %d %.1f} ",i,bm->msg.Header.nid_bg,bm->triggerpos); appendResult(es_msg_buf,data); next = next->tail; i++; } // radio messages next = es_tracksim_track.rmsgs; i = 0; while(next!=NULL) { es_TriggeredRadioMessage *rm = (es_TriggeredRadioMessage*)next->data; snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"{r %d %d %.1f} ",i,rm->msg.Header.nid_message,rm->triggerpos); appendResult(es_msg_buf,data); next = next->tail; i++; } return ES_OK; }
/* * Case-maps [srcStart..srcLimit[ but takes * context [0..srcLength[ into account. */ static void _caseMap(int32_t caseLocale, uint32_t options, UCaseMapFull *map, const uint8_t *src, UCaseContext *csc, int32_t srcStart, int32_t srcLimit, icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) { /* case mapping loop */ int32_t srcIndex=srcStart; while (U_SUCCESS(errorCode) && srcIndex<srcLimit) { int32_t cpStart; csc->cpStart=cpStart=srcIndex; UChar32 c; U8_NEXT(src, srcIndex, srcLimit, c); csc->cpLimit=srcIndex; if(c<0) { // Malformed UTF-8. ByteSinkUtil::appendUnchanged(src+cpStart, srcIndex-cpStart, sink, options, edits, errorCode); } else { const UChar *s; c=map(c, utf8_caseContextIterator, csc, &s, caseLocale); appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode); } } }
// retrieve data values from the balise message buffer es_Status es_tcl_track_radio_get(char* subcmd, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedRadioMessage_TM *rm = &es_tcl_track_radio_buf; if(!strcmp("header",subcmd)) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "{nid_message %d} {d_emergencystop %d} {d_ref %d} {d_sr %d} {m_ack %d} {m_version %d} " "{nid_em %d} {nid_lrbg %d} {q_dir %d} {q_scale %d} {radioDevice %d} {receivedSystemTime %d} " "{t_sh_rqst %d} {t_train %d} {t_train_reference}", rm->Header.nid_message, rm->Header.d_emergencystop, rm->Header.d_ref, rm->Header.d_sr, rm->Header.m_ack, rm->Header.m_version, rm->Header.nid_em, rm->Header.nid_lrbg, rm->Header.q_dir, rm->Header.q_scale, rm->Header.radioDevice, rm->Header.receivedSystemTime, rm->Header.t_sh_rqst, rm->Header.t_train, rm->Header.t_train_reference ); appendResult(es_msg_buf, data); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }
/* * Case-maps [srcStart..srcLimit[ but takes * context [0..srcLength[ into account. */ static int32_t _caseMap(const UCaseMap *csm, UCaseMapFull *map, UChar *dest, int32_t destCapacity, const UChar *src, UCaseContext *csc, int32_t srcStart, int32_t srcLimit, UErrorCode *pErrorCode) { const UChar *s; UChar32 c, c2 = 0; int32_t srcIndex, destIndex; int32_t locCache; locCache=csm->locCache; /* case mapping loop */ srcIndex=srcStart; destIndex=0; while(srcIndex<srcLimit) { csc->cpStart=srcIndex; U16_NEXT(src, srcIndex, srcLimit, c); csc->cpLimit=srcIndex; c=map(csm->csp, c, utf16_caseContextIterator, csc, &s, csm->locale, &locCache); if((destIndex<destCapacity) && (c<0 ? (c2=~c)<=0xffff : UCASE_MAX_STRING_LENGTH<c && (c2=c)<=0xffff)) { /* fast path version of appendResult() for BMP results */ dest[destIndex++]=(UChar)c2; } else { destIndex=appendResult(dest, destIndex, destCapacity, c, s); } } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
/* * Case-maps [srcStart..srcLimit[ but takes * context [0..srcLength[ into account. */ static int32_t _caseMap(const UCaseMap *csm, UCaseMapFull *map, uint8_t *dest, int32_t destCapacity, const uint8_t *src, UCaseContext *csc, int32_t srcStart, int32_t srcLimit, UErrorCode *pErrorCode) { const UChar *s; UChar32 c; int32_t srcIndex, destIndex; int32_t locCache; locCache=csm->locCache; /* case mapping loop */ srcIndex=srcStart; destIndex=0; while(srcIndex<srcLimit) { csc->cpStart=srcIndex; U8_NEXT(src, srcIndex, srcLimit, c); csc->cpLimit=srcIndex; c=map(csm->csp, c, utf8_caseContextIterator, csc, &s, csm->locale, &locCache); destIndex=appendResult(dest, destIndex, destCapacity, c, s); } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
U_CFUNC int32_t ustr_foldCase(const UCaseProps *csp, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, uint32_t options, UErrorCode *pErrorCode) { int32_t srcIndex, destIndex; const UChar *s; UChar32 c, c2 = 0; /* case mapping loop */ srcIndex=destIndex=0; while(srcIndex<srcLength) { U16_NEXT(src, srcIndex, srcLength, c); c=ucase_toFullFolding(csp, c, &s, options); if((destIndex<destCapacity) && (c<0 ? (c2=~c)<=0xffff : UCASE_MAX_STRING_LENGTH<c && (c2=c)<=0xffff)) { /* fast path version of appendResult() for BMP results */ dest[destIndex++]=(UChar)c2; } else { destIndex=appendResult(dest, destIndex, destCapacity, c, s); } } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
// retrieve data values from the radio message buffer es_Status es_tcl_track_radio_get(char* subcmd, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedRadioMessage_TM *rm = &es_tcl_track_radio_buf; if(subcmd != NULL && !strcmp("header",subcmd)) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "{nid_message %d} {d_emergencystop %d} {d_ref %d} {d_sr %d} {m_ack %d} {m_version %d} " "{nid_em %d} {nid_lrbg %d} {q_dir %d} {q_scale %d} {radioDevice %d} {receivedSystemTime %d} " "{t_sh_rqst %d} {t_train %d} {t_train_reference %d}", rm->Header.nid_message, rm->Header.d_emergencystop, rm->Header.d_ref, rm->Header.d_sr, rm->Header.m_ack, rm->Header.m_version, rm->Header.nid_em, rm->Header.nid_lrbg, rm->Header.q_dir, rm->Header.q_scale, rm->Header.radioDevice, rm->Header.receivedSystemTime, rm->Header.t_sh_rqst, rm->Header.t_train, rm->Header.t_train_reference ); appendResult(es_msg_buf, data); return ES_OK; } else if(subcmd != NULL && !strcmp("raw",subcmd) ) { int hexlen = es_tcl_track_rmsize*2; char buf[hexlen+1]; buf[hexlen] = 0; es_bytes_to_hex(es_tcl_track_rmsize, (char*)&es_tcl_track_radio_buf,buf); appendResult(buf,data); return ES_OK; } /*else if(subcmd != NULL && !strcmp("bytes",subcmd) ) { char buf[es_tcl_track_rmsize+1]; memcpy(buf,&es_tcl_track_radio_buf,es_tcl_track_rmsize); buf[es_tcl_track_rmsize] = 0; appendResult(buf,data); return ES_OK; }*/ snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header' | 'raw'",subcmd); return ES_TCL_ERROR; }
void LookupWidget::createConnections() { connect(ui_->word_input, SIGNAL(textChanged(QString)), this, SLOT(lookupWord(QString))); connect(ui_->database_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(repeatLookup())); connect(client_pool_, SIGNAL(definitionReceived(Definition)), results_, SLOT(appendResult(Definition))); connect(client_pool_, SIGNAL(matchesReceived(Matches)), this, SLOT(setCompletionItems(Matches))); connect(client_pool_, SIGNAL(databaseListReceived()), this, SLOT(updateDatabaseSelector())); }
// retrieve data values from the balise message buffer es_Status es_tcl_track_balise_get(char* subcmd, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedBaliseMessage_TM *bm = &es_tcl_track_balise_buf; if(!strcmp("header",subcmd)) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "{nid_bg %d} {n_total %d} {m_dup %d} {m_mcount %d} {m_version %d} " "{nid_c %d} {q_link %d} {q_media %d} {q_updown %d}", bm->Header.nid_bg, bm->Header.n_total, bm->Header.m_dup, bm->Header.m_mcount, bm->Header.m_version, bm->Header.nid_c, bm->Header.q_link, bm->Header.q_media, bm->Header.q_updown); appendResult(es_msg_buf, data); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }
static void U_CALLCONV ucasemap_internalUTF8Fold(int32_t /* caseLocale */, uint32_t options, UCASEMAP_BREAK_ITERATOR_UNUSED const uint8_t *src, int32_t srcLength, icu::ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) { /* case mapping loop */ int32_t srcIndex = 0; while (U_SUCCESS(errorCode) && srcIndex < srcLength) { int32_t cpStart = srcIndex; UChar32 c; U8_NEXT(src, srcIndex, srcLength, c); if(c<0) { // Malformed UTF-8. ByteSinkUtil::appendUnchanged(src+cpStart, srcIndex-cpStart, sink, options, edits, errorCode); } else { const UChar *s; c = ucase_toFullFolding(c, &s, options); appendResult(srcIndex - cpStart, c, s, sink, options, edits, errorCode); } } }
static int32_t utf8_foldCase(const UCaseProps *csp, uint8_t *dest, int32_t destCapacity, const uint8_t *src, int32_t srcLength, uint32_t options, UErrorCode *pErrorCode) { int32_t srcIndex, destIndex; const UChar *s; UChar32 c, c2; int32_t start; /* case mapping loop */ srcIndex=destIndex=0; while(srcIndex<srcLength) { start=srcIndex; U8_NEXT(src, srcIndex, srcLength, c); if(c<0) { while(destIndex<destCapacity && start<srcIndex) { dest[destIndex++]=src[start++]; } continue; } c=ucase_toFullFolding(csp, c, &s, options); if((destIndex<destCapacity) && (c<0 ? (c2=~c)<=0x7f : UCASE_MAX_STRING_LENGTH<c && (c2=c)<=0x7f)) { /* fast path version of appendResult() for ASCII results */ dest[destIndex++]=(uint8_t)c2; } else { destIndex=appendResult(dest, destIndex, destCapacity, c, s); } } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
/** * Greek string uppercasing with a state machine. * Probably simpler than a stateless function that has to figure out complex context-before * for each character. * TODO: Try to re-consolidate one way or another with the non-Greek function. */ int32_t toUpper(const UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode) { int32_t locCache = UCASE_LOC_GREEK; int32_t destIndex=0; uint32_t state = 0; for (int32_t i = 0; i < srcLength;) { int32_t nextIndex = i; UChar32 c; U16_NEXT(src, nextIndex, srcLength, c); uint32_t nextState = 0; int32_t type = ucase_getTypeOrIgnorable(csm->csp, c); if ((type & UCASE_IGNORABLE) != 0) { // c is case-ignorable nextState |= (state & AFTER_CASED); } else if (type != UCASE_NONE) { // c is cased nextState |= AFTER_CASED; } uint32_t data = getLetterData(c); if (data > 0) { uint32_t upper = data & UPPER_MASK; // Add a dialytika to this iota or ypsilon vowel // if we removed a tonos from the previous vowel, // and that previous vowel did not also have (or gain) a dialytika. // Adding one only to the final vowel in a longer sequence // (which does not occur in normal writing) would require lookahead. // Set the same flag as for preserving an existing dialytika. if ((data & HAS_VOWEL) != 0 && (state & AFTER_VOWEL_WITH_ACCENT) != 0 && (upper == 0x399 || upper == 0x3A5)) { data |= HAS_DIALYTIKA; } int32_t numYpogegrammeni = 0; // Map each one to a trailing, spacing, capital iota. if ((data & HAS_YPOGEGRAMMENI) != 0) { numYpogegrammeni = 1; } // Skip combining diacritics after this Greek letter. while (nextIndex < srcLength) { uint32_t diacriticData = getDiacriticData(src[nextIndex]); if (diacriticData != 0) { data |= diacriticData; if ((diacriticData & HAS_YPOGEGRAMMENI) != 0) { ++numYpogegrammeni; } ++nextIndex; } else { break; // not a Greek diacritic } } if ((data & HAS_VOWEL_AND_ACCENT_AND_DIALYTIKA) == HAS_VOWEL_AND_ACCENT) { nextState |= AFTER_VOWEL_WITH_ACCENT; } // Map according to Greek rules. UBool addTonos = FALSE; if (upper == 0x397 && (data & HAS_ACCENT) != 0 && numYpogegrammeni == 0 && (state & AFTER_CASED) == 0 && !isFollowedByCasedLetter(csm->csp, src, nextIndex, srcLength)) { // Keep disjunctive "or" with (only) a tonos. // We use the same "word boundary" conditions as for the Final_Sigma test. if (i == nextIndex) { upper = 0x389; // Preserve the precomposed form. } else { addTonos = TRUE; } } else if ((data & HAS_DIALYTIKA) != 0) { // Preserve a vowel with dialytika in precomposed form if it exists. if (upper == 0x399) { upper = 0x3AA; data &= ~HAS_EITHER_DIALYTIKA; } else if (upper == 0x3A5) { upper = 0x3AB; data &= ~HAS_EITHER_DIALYTIKA; } } destIndex=appendUChar(dest, destIndex, destCapacity, (UChar)upper); if (destIndex >= 0 && (data & HAS_EITHER_DIALYTIKA) != 0) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x308); // restore or add a dialytika } if (destIndex >= 0 && addTonos) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x301); } while (destIndex >= 0 && numYpogegrammeni > 0) { destIndex=appendUChar(dest, destIndex, destCapacity, 0x399); --numYpogegrammeni; } if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } else { const UChar *s; UChar32 c2 = 0; c=ucase_toFullUpper(csm->csp, c, NULL, NULL, &s, csm->locale, &locCache); if((destIndex<destCapacity) && (c<0 ? (c2=~c)<=0xffff : UCASE_MAX_STRING_LENGTH<c && (c2=c)<=0xffff)) { /* fast path version of appendResult() for BMP results */ dest[destIndex++]=(UChar)c2; } else { destIndex=appendResult(dest, destIndex, destCapacity, c, s); if(destIndex<0) { *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } } } i = nextIndex; state = nextState; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
/* * Internal titlecasing function. */ static int32_t _toTitle(UCaseMap *csm, UChar *dest, int32_t destCapacity, const UChar *src, UCaseContext *csc, int32_t srcLength, UErrorCode *pErrorCode) { const UChar *s; UChar32 c; int32_t prev, titleStart, titleLimit, idx, destIndex, length; UBool isFirstIndex; if(csm->iter!=NULL) { ubrk_setText(csm->iter, src, srcLength, pErrorCode); } else { csm->iter=ubrk_open(UBRK_WORD, csm->locale, src, srcLength, pErrorCode); } if(U_FAILURE(*pErrorCode)) { return 0; } /* set up local variables */ destIndex=0; prev=0; isFirstIndex=TRUE; /* titlecasing loop */ while(prev<srcLength) { /* find next index where to titlecase */ if(isFirstIndex) { isFirstIndex=FALSE; idx=ubrk_first(csm->iter); } else { idx=ubrk_next(csm->iter); } if(idx==UBRK_DONE || idx>srcLength) { idx=srcLength; } /* * Unicode 4 & 5 section 3.13 Default Case Operations: * * R3 toTitlecase(X): Find the word boundaries based on Unicode Standard Annex * #29, "Text Boundaries." Between each pair of word boundaries, find the first * cased character F. If F exists, map F to default_title(F); then map each * subsequent character C to default_lower(C). * * In this implementation, segment [prev..index[ into 3 parts: * a) uncased characters (copy as-is) [prev..titleStart[ * b) first case letter (titlecase) [titleStart..titleLimit[ * c) subsequent characters (lowercase) [titleLimit..index[ */ if(prev<idx) { /* find and copy uncased characters [prev..titleStart[ */ titleStart=titleLimit=prev; U16_NEXT(src, titleLimit, idx, c); if((csm->options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCASE_NONE==ucase_getType(csm->csp, c)) { /* Adjust the titlecasing index (titleStart) to the next cased character. */ for(;;) { titleStart=titleLimit; if(titleLimit==idx) { /* * only uncased characters in [prev..index[ * stop with titleStart==titleLimit==index */ break; } U16_NEXT(src, titleLimit, idx, c); if(UCASE_NONE!=ucase_getType(csm->csp, c)) { break; /* cased letter at [titleStart..titleLimit[ */ } } length=titleStart-prev; if(length>0) { if((destIndex+length)<=destCapacity) { uprv_memcpy(dest+destIndex, src+prev, length*U_SIZEOF_UCHAR); } destIndex+=length; } } if(titleStart<titleLimit) { /* titlecase c which is from [titleStart..titleLimit[ */ csc->cpStart=titleStart; csc->cpLimit=titleLimit; c=ucase_toFullTitle(csm->csp, c, utf16_caseContextIterator, csc, &s, csm->locale, &csm->locCache); destIndex=appendResult(dest, destIndex, destCapacity, c, s); /* Special case Dutch IJ titlecasing */ if ( titleStart+1 < idx && ucase_getCaseLocale(csm->locale,&csm->locCache) == UCASE_LOC_DUTCH && ( src[titleStart] == (UChar32) 0x0049 || src[titleStart] == (UChar32) 0x0069 ) && ( src[titleStart+1] == (UChar32) 0x004A || src[titleStart+1] == (UChar32) 0x006A )) { c=(UChar32) 0x004A; destIndex=appendResult(dest, destIndex, destCapacity, c, s); titleLimit++; } /* lowercase [titleLimit..index[ */ if(titleLimit<idx) { if((csm->options&U_TITLECASE_NO_LOWERCASE)==0) { /* Normal operation: Lowercase the rest of the word. */ destIndex+= _caseMap( csm, ucase_toFullLower, dest+destIndex, destCapacity-destIndex, src, csc, titleLimit, idx, pErrorCode); } else { /* Optionally just copy the rest of the word unchanged. */ length=idx-titleLimit; if((destIndex+length)<=destCapacity) { uprv_memcpy(dest+destIndex, src+titleLimit, length*U_SIZEOF_UCHAR); } destIndex+=length; } } } } prev=idx; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
// set data values in the balise message buffer es_Status es_tcl_track_balise_set(char* subcmd, char* arg, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedBaliseMessage_TM *bm = &es_tcl_track_balise_buf; // header if( subcmd != NULL && !strcmp("header",subcmd) ) { if (arg == NULL) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "invalid sub command 'set header': missing argument"); return ES_TCL_ERROR; } char *varname, *next; arg = strdup(arg); next = arg; appendResult(es_msg_buf, data); while ((varname = mystrsep(&next, " ")) != NULL) { char *v = mystrsep(&next, " "); if (v == NULL) { snprintf(es_msg_buf, ES_MSG_BUF_SIZE, "missing value for variable %s", varname); return ES_TCL_ERROR; } int value = atoi(v); if (!strcmp("nid_bg", varname)) { bm->Header.nid_bg = value; } else if (!strcmp("n_pig", varname)) { bm->Header.n_pig = value; } else if (!strcmp("n_total", varname)) { bm->Header.n_total = value; } else if (!strcmp("m_dup", varname)) { bm->Header.m_dup = value; } else if (!strcmp("m_mcount", varname)) { bm->Header.m_mcount = value; } else if (!strcmp("m_version", varname)) { bm->Header.m_version = value; } else if (!strcmp("nid_c", varname)) { bm->Header.nid_c = value; } else if (!strcmp("q_link", varname)) { bm->Header.q_link = value; } else if (!strcmp("q_media", varname)) { bm->Header.q_media = value; } else if (!strcmp("q_updown", varname)) { bm->Header.q_updown = value; } else { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid balise header variable: %s",varname); free(arg); return ES_TCL_ERROR; } } free(arg); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }
/* * Internal titlecasing function. * * Must get titleIter!=NULL. */ static int32_t _toTitle(const UCaseProps *csp, UChar *dest, int32_t destCapacity, const UChar *src, UCaseContext *csc, int32_t srcLength, UBreakIterator *titleIter, const char *locale, int32_t *locCache, UErrorCode *pErrorCode) { const UChar *s; UChar32 c; int32_t prev, titleStart, titleLimit, index, destIndex, length; UBool isFirstIndex; /* set up local variables */ destIndex=0; prev=0; isFirstIndex=TRUE; /* titlecasing loop */ while(prev<srcLength) { /* find next index where to titlecase */ if(isFirstIndex) { isFirstIndex=FALSE; index=ubrk_first(titleIter); } else { index=ubrk_next(titleIter); } if(index==UBRK_DONE || index>srcLength) { index=srcLength; } /* * Unicode 4 & 5 section 3.13 Default Case Operations: * * R3 toTitlecase(X): Find the word boundaries based on Unicode Standard Annex * #29, "Text Boundaries." Between each pair of word boundaries, find the first * cased character F. If F exists, map F to default_title(F); then map each * subsequent character C to default_lower(C). * * In this implementation, segment [prev..index[ into 3 parts: * a) uncased characters (copy as-is) [prev..titleStart[ * b) first case letter (titlecase) [titleStart..titleLimit[ * c) subsequent characters (lowercase) [titleLimit..index[ */ if(prev<index) { /* find and copy uncased characters [prev..titleStart[ */ titleStart=titleLimit=prev; for(;;) { U16_NEXT(src, titleLimit, srcLength, c); if(UCASE_NONE!=ucase_getType(csp, c)) { break; /* cased letter at [titleStart..titleLimit[ */ } titleStart=titleLimit; if(titleLimit==index) { /* * only uncased characters in [prev..index[ * stop with titleStart==titleLimit==index */ break; } } length=titleStart-prev; if(length>0) { if((destIndex+length)<=destCapacity) { uprv_memcpy(dest+destIndex, src+prev, length*U_SIZEOF_UCHAR); } destIndex+=length; } if(titleStart<titleLimit) { /* titlecase c which is from [titleStart..titleLimit[ */ csc->cpStart=titleStart; csc->cpLimit=titleLimit; c=ucase_toFullTitle(csp, c, utf16_caseContextIterator, csc, &s, locale, locCache); destIndex=appendResult(dest, destIndex, destCapacity, c, s); /* lowercase [titleLimit..index[ */ if(titleLimit<index) { destIndex+= _caseMap( csp, ucase_toFullLower, dest+destIndex, destCapacity-destIndex, src, csc, titleLimit, index, locale, locCache, pErrorCode); } } } prev=index; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
// set data values in the radio message buffer es_Status es_tcl_track_radio_set(char* subcmd, char* arg, void (*appendResult)(char*, es_ClientData), es_ClientData data) { CompressedRadioMessage_TM *rm = &es_tcl_track_radio_buf; // header if( subcmd != NULL && !strcmp("header",subcmd) ) { if(arg==NULL) { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command 'set header': missing argument"); return ES_TCL_ERROR; } char *varname, *next; arg = strdup(arg); next = arg; appendResult(es_msg_buf,data); while((varname = mystrsep(&next," ")) != NULL) { char *v = mystrsep(&next," "); if( v == NULL ) { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"missing value for variable %s",varname); return ES_TCL_ERROR; } int value = atoi(v); if( !strcmp("nid_message",varname) ) { rm->Header.nid_message = value; } else if( !strcmp("d_emergencystop",varname) ) { rm->Header.d_emergencystop = value; } else if( !strcmp("d_ref",varname) ) { rm->Header.d_ref = value; } else if( !strcmp("d_sr",varname) ) { rm->Header.d_sr = value; } else if( !strcmp("m_ack",varname) ) { rm->Header.m_ack = value; } else if( !strcmp("m_version",varname) ) { rm->Header.m_version = value; } else if( !strcmp("nid_em",varname) ) { rm->Header.nid_em = value; } else if( !strcmp("nid_lrbg",varname) ) { rm->Header.nid_lrbg = value; } else if( !strcmp("q_dir",varname) ) { rm->Header.q_dir = value; } else if( !strcmp("q_scale",varname) ) { rm->Header.q_scale = value; } else if( !strcmp("radioDevice",varname) ) { rm->Header.radioDevice = value; } else if( !strcmp("receivedSystemTime",varname) ) { rm->Header.receivedSystemTime = value; } else if( !strcmp("t_sh_rqst",varname) ) { rm->Header.t_sh_rqst = value; } else if( !strcmp("t_train",varname) ) { rm->Header.t_train = value; } else if( !strcmp("t_train_reference",varname) ) { rm->Header.t_train_reference = value; } else { snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid radio header variable: %s",varname); free(arg); return ES_TCL_ERROR; } } free(arg); return ES_OK; } snprintf(es_msg_buf,ES_MSG_BUF_SIZE,"invalid sub command '%s': expected 'header'",subcmd); return ES_TCL_ERROR; }
es_Status es_tcl_track_title_get(void (*appendResult)(char* res, es_ClientData data), es_ClientData data) { if( es_tracksim_track.title != NULL ) { appendResult(es_tracksim_track.title,data); } return ES_OK; }
U_CFUNC int32_t U_CALLCONV ucasemap_internalUTF8ToTitle(const UCaseMap *csm, uint8_t *dest, int32_t destCapacity, const uint8_t *src, int32_t srcLength, UErrorCode *pErrorCode) { const UChar *s; UChar32 c; int32_t prev, titleStart, titleLimit, idx, destIndex, length; UBool isFirstIndex; if(U_FAILURE(*pErrorCode)) { return 0; } // Use the C++ abstract base class to minimize dependencies. // TODO: Change UCaseMap.iter to store a BreakIterator directly. BreakIterator *bi=reinterpret_cast<BreakIterator *>(csm->iter); /* set up local variables */ int32_t locCache=csm->locCache; UCaseContext csc=UCASECONTEXT_INITIALIZER; csc.p=(void *)src; csc.limit=srcLength; destIndex=0; prev=0; isFirstIndex=TRUE; /* titlecasing loop */ while(prev<srcLength) { /* find next index where to titlecase */ if(isFirstIndex) { isFirstIndex=FALSE; idx=bi->first(); } else { idx=bi->next(); } if(idx==UBRK_DONE || idx>srcLength) { idx=srcLength; } /* * Unicode 4 & 5 section 3.13 Default Case Operations: * * R3 toTitlecase(X): Find the word boundaries based on Unicode Standard Annex * #29, "Text Boundaries." Between each pair of word boundaries, find the first * cased character F. If F exists, map F to default_title(F); then map each * subsequent character C to default_lower(C). * * In this implementation, segment [prev..index[ into 3 parts: * a) uncased characters (copy as-is) [prev..titleStart[ * b) first case letter (titlecase) [titleStart..titleLimit[ * c) subsequent characters (lowercase) [titleLimit..index[ */ if(prev<idx) { /* find and copy uncased characters [prev..titleStart[ */ titleStart=titleLimit=prev; U8_NEXT(src, titleLimit, idx, c); if((csm->options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0 && UCASE_NONE==ucase_getType(csm->csp, c)) { /* Adjust the titlecasing index (titleStart) to the next cased character. */ for(;;) { titleStart=titleLimit; if(titleLimit==idx) { /* * only uncased characters in [prev..index[ * stop with titleStart==titleLimit==index */ break; } U8_NEXT(src, titleLimit, idx, c); if(UCASE_NONE!=ucase_getType(csm->csp, c)) { break; /* cased letter at [titleStart..titleLimit[ */ } } length=titleStart-prev; if(length>0) { if((destIndex+length)<=destCapacity) { uprv_memcpy(dest+destIndex, src+prev, length); } destIndex+=length; } } if(titleStart<titleLimit) { /* titlecase c which is from [titleStart..titleLimit[ */ csc.cpStart=titleStart; csc.cpLimit=titleLimit; c=ucase_toFullTitle(csm->csp, c, utf8_caseContextIterator, &csc, &s, csm->locale, &locCache); destIndex=appendResult(dest, destIndex, destCapacity, c, s); /* Special case Dutch IJ titlecasing */ if ( titleStart+1 < idx && ucase_getCaseLocale(csm->locale, &locCache) == UCASE_LOC_DUTCH && ( src[titleStart] == 0x0049 || src[titleStart] == 0x0069 ) && ( src[titleStart+1] == 0x004A || src[titleStart+1] == 0x006A )) { c=0x004A; destIndex=appendResult(dest, destIndex, destCapacity, c, s); titleLimit++; } /* lowercase [titleLimit..index[ */ if(titleLimit<idx) { if((csm->options&U_TITLECASE_NO_LOWERCASE)==0) { /* Normal operation: Lowercase the rest of the word. */ destIndex+= _caseMap( csm, ucase_toFullLower, dest+destIndex, destCapacity-destIndex, src, &csc, titleLimit, idx, pErrorCode); } else { /* Optionally just copy the rest of the word unchanged. */ length=idx-titleLimit; if((destIndex+length)<=destCapacity) { uprv_memcpy(dest+destIndex, src+titleLimit, length); } destIndex+=length; } } } } prev=idx; } if(destIndex>destCapacity) { *pErrorCode=U_BUFFER_OVERFLOW_ERROR; } return destIndex; }
U_CFUNC void U_CALLCONV ucasemap_internalUTF8ToTitle( int32_t caseLocale, uint32_t options, BreakIterator *iter, const uint8_t *src, int32_t srcLength, ByteSink &sink, icu::Edits *edits, UErrorCode &errorCode) { if (!ustrcase_checkTitleAdjustmentOptions(options, errorCode)) { return; } /* set up local variables */ UCaseContext csc=UCASECONTEXT_INITIALIZER; csc.p=(void *)src; csc.limit=srcLength; int32_t prev=0; UBool isFirstIndex=TRUE; /* titlecasing loop */ while(prev<srcLength) { /* find next index where to titlecase */ int32_t index; if(isFirstIndex) { isFirstIndex=FALSE; index=iter->first(); } else { index=iter->next(); } if(index==UBRK_DONE || index>srcLength) { index=srcLength; } /* * Segment [prev..index[ into 3 parts: * a) skipped characters (copy as-is) [prev..titleStart[ * b) first letter (titlecase) [titleStart..titleLimit[ * c) subsequent characters (lowercase) [titleLimit..index[ */ if(prev<index) { /* find and copy skipped characters [prev..titleStart[ */ int32_t titleStart=prev; int32_t titleLimit=prev; UChar32 c; U8_NEXT(src, titleLimit, index, c); if ((options&U_TITLECASE_NO_BREAK_ADJUSTMENT)==0) { // Adjust the titlecasing index to the next cased character, // or to the next letter/number/symbol/private use. // Stop with titleStart<titleLimit<=index // if there is a character to be titlecased, // or else stop with titleStart==titleLimit==index. UBool toCased = (options&U_TITLECASE_ADJUST_TO_CASED) != 0; while (toCased ? UCASE_NONE==ucase_getType(c) : !ustrcase_isLNS(c)) { titleStart=titleLimit; if(titleLimit==index) { break; } U8_NEXT(src, titleLimit, index, c); } if (prev < titleStart) { if (!ByteSinkUtil::appendUnchanged(src+prev, titleStart-prev, sink, options, edits, errorCode)) { return; } } } if(titleStart<titleLimit) { /* titlecase c which is from [titleStart..titleLimit[ */ if(c>=0) { csc.cpStart=titleStart; csc.cpLimit=titleLimit; const UChar *s; c=ucase_toFullTitle(c, utf8_caseContextIterator, &csc, &s, caseLocale); if (!appendResult(titleLimit-titleStart, c, s, sink, options, edits, errorCode)) { return; } } else { // Malformed UTF-8. if (!ByteSinkUtil::appendUnchanged(src+titleStart, titleLimit-titleStart, sink, options, edits, errorCode)) { return; } } /* Special case Dutch IJ titlecasing */ if (titleStart+1 < index && caseLocale == UCASE_LOC_DUTCH && (src[titleStart] == 0x0049 || src[titleStart] == 0x0069)) { if (src[titleStart+1] == 0x006A) { ByteSinkUtil::appendCodePoint(1, 0x004A, sink, edits); titleLimit++; } else if (src[titleStart+1] == 0x004A) { // Keep the capital J from getting lowercased. if (!ByteSinkUtil::appendUnchanged(src+titleStart+1, 1, sink, options, edits, errorCode)) { return; } titleLimit++; } } /* lowercase [titleLimit..index[ */ if(titleLimit<index) { if((options&U_TITLECASE_NO_LOWERCASE)==0) { /* Normal operation: Lowercase the rest of the word. */ _caseMap(caseLocale, options, ucase_toFullLower, src, &csc, titleLimit, index, sink, edits, errorCode); if(U_FAILURE(errorCode)) { return; } } else { /* Optionally just copy the rest of the word unchanged. */ if (!ByteSinkUtil::appendUnchanged(src+titleLimit, index-titleLimit, sink, options, edits, errorCode)) { return; } } } } } prev=index; } }
// Keep this consistent with the UTF-16 version in ustrcase.cpp and the Java version in CaseMap.java. void toUpper(uint32_t options, const uint8_t *src, int32_t srcLength, ByteSink &sink, Edits *edits, UErrorCode &errorCode) { uint32_t state = 0; for (int32_t i = 0; i < srcLength;) { int32_t nextIndex = i; UChar32 c; U8_NEXT(src, nextIndex, srcLength, c); uint32_t nextState = 0; int32_t type = ucase_getTypeOrIgnorable(c); if ((type & UCASE_IGNORABLE) != 0) { // c is case-ignorable nextState |= (state & AFTER_CASED); } else if (type != UCASE_NONE) { // c is cased nextState |= AFTER_CASED; } uint32_t data = getLetterData(c); if (data > 0) { uint32_t upper = data & UPPER_MASK; // Add a dialytika to this iota or ypsilon vowel // if we removed a tonos from the previous vowel, // and that previous vowel did not also have (or gain) a dialytika. // Adding one only to the final vowel in a longer sequence // (which does not occur in normal writing) would require lookahead. // Set the same flag as for preserving an existing dialytika. if ((data & HAS_VOWEL) != 0 && (state & AFTER_VOWEL_WITH_ACCENT) != 0 && (upper == 0x399 || upper == 0x3A5)) { data |= HAS_DIALYTIKA; } int32_t numYpogegrammeni = 0; // Map each one to a trailing, spacing, capital iota. if ((data & HAS_YPOGEGRAMMENI) != 0) { numYpogegrammeni = 1; } // Skip combining diacritics after this Greek letter. int32_t nextNextIndex = nextIndex; while (nextIndex < srcLength) { UChar32 c2; U8_NEXT(src, nextNextIndex, srcLength, c2); uint32_t diacriticData = getDiacriticData(c2); if (diacriticData != 0) { data |= diacriticData; if ((diacriticData & HAS_YPOGEGRAMMENI) != 0) { ++numYpogegrammeni; } nextIndex = nextNextIndex; } else { break; // not a Greek diacritic } } if ((data & HAS_VOWEL_AND_ACCENT_AND_DIALYTIKA) == HAS_VOWEL_AND_ACCENT) { nextState |= AFTER_VOWEL_WITH_ACCENT; } // Map according to Greek rules. UBool addTonos = FALSE; if (upper == 0x397 && (data & HAS_ACCENT) != 0 && numYpogegrammeni == 0 && (state & AFTER_CASED) == 0 && !isFollowedByCasedLetter(src, nextIndex, srcLength)) { // Keep disjunctive "or" with (only) a tonos. // We use the same "word boundary" conditions as for the Final_Sigma test. if (i == nextIndex) { upper = 0x389; // Preserve the precomposed form. } else { addTonos = TRUE; } } else if ((data & HAS_DIALYTIKA) != 0) { // Preserve a vowel with dialytika in precomposed form if it exists. if (upper == 0x399) { upper = 0x3AA; data &= ~HAS_EITHER_DIALYTIKA; } else if (upper == 0x3A5) { upper = 0x3AB; data &= ~HAS_EITHER_DIALYTIKA; } } UBool change; if (edits == nullptr && (options & U_OMIT_UNCHANGED_TEXT) == 0) { change = TRUE; // common, simple usage } else { // Find out first whether we are changing the text. U_ASSERT(0x370 <= upper && upper <= 0x3ff); // 2-byte UTF-8, main Greek block change = (i + 2) > nextIndex || src[i] != getTwoByteLead(upper) || src[i + 1] != getTwoByteTrail(upper) || numYpogegrammeni > 0; int32_t i2 = i + 2; if ((data & HAS_EITHER_DIALYTIKA) != 0) { change |= (i2 + 2) > nextIndex || src[i2] != (uint8_t)u8"\u0308"[0] || src[i2 + 1] != (uint8_t)u8"\u0308"[1]; i2 += 2; } if (addTonos) { change |= (i2 + 2) > nextIndex || src[i2] != (uint8_t)u8"\u0301"[0] || src[i2 + 1] != (uint8_t)u8"\u0301"[1]; i2 += 2; } int32_t oldLength = nextIndex - i; int32_t newLength = (i2 - i) + numYpogegrammeni * 2; // 2 bytes per U+0399 change |= oldLength != newLength; if (change) { if (edits != NULL) { edits->addReplace(oldLength, newLength); } } else { if (edits != NULL) { edits->addUnchanged(oldLength); } // Write unchanged text? change = (options & U_OMIT_UNCHANGED_TEXT) == 0; } } if (change) { ByteSinkUtil::appendTwoBytes(upper, sink); if ((data & HAS_EITHER_DIALYTIKA) != 0) { sink.Append(u8"\u0308", 2); // restore or add a dialytika } if (addTonos) { sink.Append(u8"\u0301", 2); } while (numYpogegrammeni > 0) { sink.Append(u8"\u0399", 2); --numYpogegrammeni; } } } else if(c>=0) { const UChar *s; c=ucase_toFullUpper(c, NULL, NULL, &s, UCASE_LOC_GREEK); if (!appendResult(nextIndex - i, c, s, sink, options, edits, errorCode)) { return; } } else { // Malformed UTF-8. if (!ByteSinkUtil::appendUnchanged(src+i, nextIndex-i, sink, options, edits, errorCode)) { return; } } i = nextIndex; state = nextState; } }