Lines Matching refs:states
156 /* adjust "final valid" states according to the state flags */
188 ucm_addState(UCMStates *states, const char *s) {
191 if(states->countStates==MBCS_MAX_STATE_COUNT) {
192 fprintf(stderr, "ucm error: too many states (maximum %u)\n", MBCS_MAX_STATE_COUNT);
196 error=parseState(s, states->stateTable[states->countStates],
197 &states->stateFlags[states->countStates]);
203 ++states->countStates;
209 UCMStates *states;
213 states=&ucm->states;
267 states->conversionType=UCNV_DBCS;
269 states->conversionType = UCNV_SBCS;
271 states->conversionType = UCNV_MBCS;
273 states->conversionType = UCNV_EBCDIC_STATEFUL;
282 states->maxCharLength=(int8_t)(c-'0');
283 states->outputType=(int8_t)(states->maxCharLength-1);
292 states->minCharLength=(int8_t)(c-'0');
300 switch(states->conversionType) {
304 states->conversionType=UCNV_MBCS;
313 if(states->maxCharLength==0) {
317 ucm_addState(states, *pValue);
334 sumUpStates(UCMStates *states) {
339 * Sum up the offsets for all states.
347 for(count=states->countStates; !allStatesReady && count>=0; --count) {
349 for(state=states->countStates-1; state>=0; --state) {
350 if(!(states->stateFlags[state]&MBCS_STATE_FLAG_READY)) {
356 entry=states->stateTable[state][cell];
360 states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_VALUE(entry, sum);
364 states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_VALUE(entry, sum);
376 entry=states->stateTable[state][cell];
378 if(states->stateFlags[MBCS_ENTRY_TRANSITION_STATE(entry)]&MBCS_STATE_FLAG_READY) {
379 states->stateTable[state][cell]=MBCS_ENTRY_TRANSITION_SET_OFFSET(entry, sum);
380 sum+=states->stateOffsetSum[MBCS_ENTRY_TRANSITION_STATE(entry)];
390 states->stateOffsetSum[state]=sum;
391 states->stateFlags[state]|=MBCS_STATE_FLAG_READY;
403 * For all "direct" (i.e., initial) states>0,
405 * the previous initial states.
407 sum=states->stateOffsetSum[0];
408 for(state=1; state<states->countStates; ++state) {
409 if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) {
411 sum+=states->stateOffsetSum[state];
413 entry=states->stateTable[state][cell];
415 states->stateTable[state][cell]=MBCS_ENTRY_TRANSITION_ADD_OFFSET(entry, sum2);
422 return states->countToUCodeUnits=(sum+1)&~1;
426 ucm_processStates(UCMStates *states, UBool ignoreSISOCheck) {
429 if(states->conversionType==UCNV_UNSUPPORTED_CONVERTER) {
434 if(states->countStates==0) {
435 switch(states->conversionType) {
438 if(states->maxCharLength!=1) {
442 states->conversionType=UCNV_MBCS;
443 ucm_addState(states, "0-ff");
451 if(states->minCharLength!=1 || states->maxCharLength!=2) {
455 states->conversionType=UCNV_MBCS;
456 ucm_addState(states, "0-ff, e:1.s, f:0.s");
457 ucm_addState(states, "initial, 0-3f:4, e:1.s, f:0.s, 40:3, 41-fe:2, ff:4");
458 ucm_addState(states, "0-40:1.i, 41-fe:1., ff:1.i");
459 ucm_addState(states, "0-ff:1.i, 40:1.");
460 ucm_addState(states, "0-ff:1.i");
464 states->minCharLength!=2 || states->maxCharLength!=2) {
468 states->conversionType = UCNV_MBCS;
469 ucm_addState(states, "0-3f:3, 40:2, 41-fe:1, ff:3");
470 ucm_addState(states, "41-fe");
471 ucm_addState(states, "40");
472 ucm_addState(states, "");
487 if(states->maxCharLength<states->minCharLength) {
492 /* count non-direct states and compare with max B/char */
494 for(state=0; state<states->countStates; ++state) {
495 if((states->stateFlags[state]&0xf)!=MBCS_STATE_FLAG_DIRECT) {
499 if(states->maxCharLength>count+1) {
504 if(states->minCharLength==1) {
509 * then the initial state must have direct result states
512 entry=states->stateTable[0][cell];
528 * and that all next states after final ones have the "direct"
529 * flag of initial states
531 for(state=states->countStates-1; state>=0; --state) {
533 entry=states->stateTable[state][cell];
534 if((uint8_t)MBCS_ENTRY_STATE(entry)>=states->countStates) {
539 if(MBCS_ENTRY_IS_FINAL(entry) && (states->stateFlags[MBCS_ENTRY_STATE(entry)]&0xf)!=MBCS_STATE_FLAG_DIRECT) {
543 } else if(MBCS_ENTRY_IS_TRANSITION(entry) && (states->stateFlags[MBCS_ENTRY_STATE(entry)]&0xf)==MBCS_STATE_FLAG_DIRECT) {
552 if(states->countStates>=2 && (states->stateFlags[1]&0xf)==MBCS_STATE_FLAG_DIRECT) {
553 if(states->maxCharLength!=2) {
554 fprintf(stderr, "ucm error: SI/SO codepages must have max 2 bytes/char (not %x)\n", (int)states->maxCharLength);
557 if(states->countStates<3) {
558 fprintf(stderr, "ucm error: SI/SO codepages must have at least 3 states (not %x)\n", (int)states->countStates);
563 (states->stateTable[0][0xe]==MBCS_ENTRY_FINAL(1, MBCS_STATE_CHANGE_ONLY, 0) &&
564 states->stateTable[0][0xf]==MBCS_ENTRY_FINAL(0, MBCS_STATE_CHANGE_ONLY, 0) &&
565 states->stateTable[1][0xe]==MBCS_ENTRY_FINAL(1, MBCS_STATE_CHANGE_ONLY, 0) &&
566 states->stateTable[1][0xf]==MBCS_ENTRY_FINAL(0, MBCS_STATE_CHANGE_ONLY, 0))
568 states->outputType=MBCS_OUTPUT_2_SISO;
570 fprintf(stderr, "ucm error: SI/SO codepages must have in states 0 and 1 transitions e:1.s, f:0.s\n");
579 while(state<states->countStates) {
580 if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) {
587 sumUpStates(states);
616 compactToUnicode2(UCMStates *states,
628 if(states->outputType==MBCS_OUTPUT_2_SISO) {
638 entry=states->stateTable[leadState][i];
644 for(i=1; i<states->countStates; ++i) {
655 entry=states->stateTable[leadState][i];
661 entry=states->stateTable[trailState][j];
699 if(states->countStates>=MBCS_MAX_STATE_COUNT) {
700 fprintf(stderr, "cannot compact toUnicode because the maximum number of states is reached\n");
705 oldStateTable=(int32_t (*)[256])uprv_malloc(states->countStates*1024);
710 uprv_memcpy(oldStateTable, states->stateTable, states->countStates*1024);
717 newState=states->countStates++;
718 states->stateFlags[newState]=0;
719 /* copy the old trail state, turning all assigned states into unassigned ones */
721 entry=states->stateTable[trailState][i];
725 states->stateTable[newState][i]=MBCS_ENTRY_FINAL_SET_ACTION_VALUE(entry, MBCS_STATE_UNASSIGNED, 0xfffe);
728 states->stateTable[newState][i]=entry;
736 states->stateTable[leadState][i]=MBCS_ENTRY_SET_STATE(states->stateTable[leadState][i], newState);
741 for(i=0; i<states->countStates; ++i) {
742 states->stateFlags[i]&=~MBCS_STATE_FLAG_READY;
744 sum=sumUpStates(states);
762 --states->countStates;
763 uprv_memcpy(states->stateTable, oldStateTable, states->countStates*1024);
773 * The old state table has the same lead _and_ trail states for assigned characters!
774 * The differences are in the offsets, and in the trail states for some unassigned characters.
781 for(leadState=0; leadState<states->countStates; ++leadState) {
782 if((states->stateFlags[leadState]&0xf)==MBCS_STATE_FLAG_DIRECT) {
785 entry=states->stateTable[leadState][i];
788 /* the new state does not have assigned states */
794 entry=states->stateTable[trailState][j];
842 findUnassigned(UCMStates *states,
852 entry=states->stateTable[state][i];
854 savings=findUnassigned(states,
899 compactToUnicodeHelper(UCMStates *states,
905 for(state=0; state<states->countStates; ++state) {
906 if((states->stateFlags[state]&0xf)==MBCS_STATE_FLAG_DIRECT) {
907 savings=findUnassigned(states,
925 ucm_optimizeStates(UCMStates *states,
933 for(state=0; state<states->countStates; ++state) {
935 entry=states->stateTable[state][cell];
942 states->stateTable[state][cell]=MBCS_ENTRY_FINAL_SET_ACTION(entry, MBCS_STATE_UNASSIGNED);
948 if(states->maxCharLength==2) {
949 compactToUnicode2(states, pUnicodeCodeUnits, toUFallbacks, countToUFallbacks, verbose);
950 } else if(states->maxCharLength>2) {
952 compactToUnicodeHelper(states, *pUnicodeCodeUnits, toUFallbacks, countToUFallbacks);
974 ucm_countChars(UCMStates *states,
984 if(states->countStates==0) {
990 if(length==2 && states->outputType==MBCS_OUTPUT_2_SISO) {
1000 entry=states->stateTable[state][bytes[i]];
1041 if(count>1 && states->outputType==MBCS_OUTPUT_2_SISO && length!=2*count) {