bool OBResidue::GetAminoAcidProperty(int property) const { switch(property) { case OBAminoAcidProperty::ACIDIC: return IS_ACIDIC(_aakey) != 0; case OBAminoAcidProperty::ACYCLIC: return IS_ACYCLIC(_aakey) != 0; case OBAminoAcidProperty::ALIPHATIC: return IS_ALIPHATIC(_aakey) != 0; case OBAminoAcidProperty::AROMATIC: return IS_AROMATIC(_aakey) != 0; case OBAminoAcidProperty::BASIC: return IS_BASIC(_aakey) != 0; case OBAminoAcidProperty::BURIED: return IS_BURIED(_aakey) != 0; case OBAminoAcidProperty::CHARGED: return IS_CHARGED(_aakey) != 0; case OBAminoAcidProperty::CYCLIC: return IS_CYCLIC(_aakey) != 0; case OBAminoAcidProperty::HYDROPHOBIC: return IS_HYDROPHOBIC(_aakey) != 0; case OBAminoAcidProperty::LARGE: return IS_LARGE(_aakey) != 0; case OBAminoAcidProperty::MEDIUM: return IS_MEDIUM(_aakey) != 0; case OBAminoAcidProperty::NEGATIVE: return IS_NEGATIVE(_aakey) != 0; case OBAminoAcidProperty::NEUTRAL: return IS_NEUTRAL(_aakey) != 0; case OBAminoAcidProperty::POLAR: return IS_POLAR(_aakey) != 0; case OBAminoAcidProperty::POSITIVE: return IS_POSITIVE(_aakey) != 0; case OBAminoAcidProperty::SMALL: return IS_SMALL(_aakey) != 0; case OBAminoAcidProperty::SURFACE: return IS_SURFACE(_aakey) != 0; default: return false; } }
U_CFUNC int32_t u_strFromPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, UBool *caseFlags, UErrorCode *pErrorCode) { int32_t n, destLength, i, bias, basicLength, j, in, oldi, w, k, digit, t, destCPCount, firstSupplementaryIndex, cpLength; UChar b; /* argument checking */ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; } if(src==NULL || srcLength<-1 || (dest==NULL && destCapacity!=0)) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } if(srcLength==-1) { srcLength=u_strlen(src); } /* * Handle the basic code points: * Let basicLength be the number of input code points * before the last delimiter, or 0 if there is none, * then copy the first basicLength code points to the output. * * The two following loops iterate backward. */ for(j=srcLength; j>0;) { if(src[--j]==DELIMITER) { break; } } destLength=basicLength=destCPCount=j; U_ASSERT(destLength>=0); while(j>0) { b=src[--j]; if(!IS_BASIC(b)) { *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } if(j<destCapacity) { dest[j]=(UChar)b; if(caseFlags!=NULL) { caseFlags[j]=IS_BASIC_UPPERCASE(b); } } } /* Initialize the state: */ n=INITIAL_N; i=0; bias=INITIAL_BIAS; firstSupplementaryIndex=1000000000; /* * Main decoding loop: * Start just after the last delimiter if any * basic code points were copied; start at the beginning otherwise. */ for(in=basicLength>0 ? basicLength+1 : 0; in<srcLength; /* no op */) { /* * in is the index of the next character to be consumed, and * destCPCount is the number of code points in the output array. * * Decode a generalized variable-length integer into delta, * which gets added to i. The overflow checking is easier * if we increase i as we go, then subtract off its starting * value at the end to obtain delta. */ for(oldi=i, w=1, k=BASE; /* no condition */; k+=BASE) { if(in>=srcLength) { *pErrorCode=U_ILLEGAL_CHAR_FOUND; return 0; } digit=basicToDigit[(uint8_t)src[in++]]; if(digit<0) { *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } if(digit>(0x7fffffff-i)/w) { /* integer overflow */ *pErrorCode=U_ILLEGAL_CHAR_FOUND; return 0; } i+=digit*w; /** RAM: comment out the old code for conformance with draft-ietf-idn-punycode-03.txt t=k-bias; if(t<TMIN) { t=TMIN; } else if(t>TMAX) { t=TMAX; } */ t=k-bias; if(t<TMIN) { t=TMIN; } else if(k>=(bias+TMAX)) { t=TMAX; } if(digit<t) { break; } if(w>0x7fffffff/(BASE-t)) { /* integer overflow */ *pErrorCode=U_ILLEGAL_CHAR_FOUND; return 0; } w*=BASE-t; } /* * Modification from sample code: * Increments destCPCount here, * where needed instead of in for() loop tail. */ ++destCPCount; bias=adaptBias(i-oldi, destCPCount, (UBool)(oldi==0)); /* * i was supposed to wrap around from (incremented) destCPCount to 0, * incrementing n each time, so we'll fix that now: */ if(i/destCPCount>(0x7fffffff-n)) { /* integer overflow */ *pErrorCode=U_ILLEGAL_CHAR_FOUND; return 0; } n+=i/destCPCount; i%=destCPCount; /* not needed for Punycode: */ /* if (decode_digit(n) <= BASE) return punycode_invalid_input; */ if(n>0x10ffff || U_IS_SURROGATE(n)) { /* Unicode code point overflow */ *pErrorCode=U_ILLEGAL_CHAR_FOUND; return 0; } /* Insert n at position i of the output: */ cpLength=U16_LENGTH(n); if(dest!=NULL && ((destLength+cpLength)<=destCapacity)) { int32_t codeUnitIndex; /* * Handle indexes when supplementary code points are present. * * In almost all cases, there will be only BMP code points before i * and even in the entire string. * This is handled with the same efficiency as with UTF-32. * * Only the rare cases with supplementary code points are handled * more slowly - but not too bad since this is an insertion anyway. */ if(i<=firstSupplementaryIndex) { codeUnitIndex=i; if(cpLength>1) { firstSupplementaryIndex=codeUnitIndex; } else { ++firstSupplementaryIndex; } } else { codeUnitIndex=firstSupplementaryIndex; U16_FWD_N(dest, codeUnitIndex, destLength, i-codeUnitIndex); } /* use the UChar index codeUnitIndex instead of the code point index i */ if(codeUnitIndex<destLength) { uprv_memmove(dest+codeUnitIndex+cpLength, dest+codeUnitIndex, (destLength-codeUnitIndex)*U_SIZEOF_UCHAR); if(caseFlags!=NULL) { uprv_memmove(caseFlags+codeUnitIndex+cpLength, caseFlags+codeUnitIndex, destLength-codeUnitIndex); } } if(cpLength==1) { /* BMP, insert one code unit */ dest[codeUnitIndex]=(UChar)n; } else { /* supplementary character, insert two code units */ dest[codeUnitIndex]=U16_LEAD(n); dest[codeUnitIndex+1]=U16_TRAIL(n); } if(caseFlags!=NULL) { /* Case of last character determines uppercase flag: */ caseFlags[codeUnitIndex]=IS_BASIC_UPPERCASE(src[in-1]); if(cpLength==2) { caseFlags[codeUnitIndex+1]=FALSE; } } } destLength+=cpLength; U_ASSERT(destLength>=0); ++i; } return u_terminateUChars(dest, destCapacity, destLength, pErrorCode); }
U_CFUNC int32_t u_strToPunycode(const UChar *src, int32_t srcLength, UChar *dest, int32_t destCapacity, const UBool *caseFlags, UErrorCode *pErrorCode) { int32_t cpBuffer[MAX_CP_COUNT]; int32_t n, delta, handledCPCount, basicLength, destLength, bias, j, m, q, k, t, srcCPCount; UChar c, c2; /* argument checking */ if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) { return 0; } if(src==NULL || srcLength<-1 || (dest==NULL && destCapacity!=0)) { *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR; return 0; } /* * Handle the basic code points and * convert extended ones to UTF-32 in cpBuffer (caseFlag in sign bit): */ srcCPCount=destLength=0; if(srcLength==-1) { /* NUL-terminated input */ for(j=0; /* no condition */; ++j) { if((c=src[j])==0) { break; } if(srcCPCount==MAX_CP_COUNT) { /* too many input code points */ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } if(IS_BASIC(c)) { cpBuffer[srcCPCount++]=0; if(destLength<destCapacity) { dest[destLength]= caseFlags!=NULL ? asciiCaseMap((char)c, caseFlags[j]) : (char)c; } ++destLength; } else { n=(caseFlags!=NULL && caseFlags[j])<<31L; if(U16_IS_SINGLE(c)) { n|=c; } else if(U16_IS_LEAD(c) && U16_IS_TRAIL(c2=src[j+1])) { ++j; n|=(int32_t)U16_GET_SUPPLEMENTARY(c, c2); } else { /* error: unmatched surrogate */ *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } cpBuffer[srcCPCount++]=n; } } } else { /* length-specified input */ for(j=0; j<srcLength; ++j) { if(srcCPCount==MAX_CP_COUNT) { /* too many input code points */ *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR; return 0; } c=src[j]; if(IS_BASIC(c)) { cpBuffer[srcCPCount++]=0; if(destLength<destCapacity) { dest[destLength]= caseFlags!=NULL ? asciiCaseMap((char)c, caseFlags[j]) : (char)c; } ++destLength; } else { n=(caseFlags!=NULL && caseFlags[j])<<31L; if(U16_IS_SINGLE(c)) { n|=c; } else if(U16_IS_LEAD(c) && (j+1)<srcLength && U16_IS_TRAIL(c2=src[j+1])) { ++j; n|=(int32_t)U16_GET_SUPPLEMENTARY(c, c2); } else { /* error: unmatched surrogate */ *pErrorCode=U_INVALID_CHAR_FOUND; return 0; } cpBuffer[srcCPCount++]=n; } } } /* Finish the basic string - if it is not empty - with a delimiter. */ basicLength=destLength; if(basicLength>0) { if(destLength<destCapacity) { dest[destLength]=DELIMITER; } ++destLength; } /* * handledCPCount is the number of code points that have been handled * basicLength is the number of basic code points * destLength is the number of chars that have been output */ /* Initialize the state: */ n=INITIAL_N; delta=0; bias=INITIAL_BIAS; /* Main encoding loop: */ for(handledCPCount=basicLength; handledCPCount<srcCPCount; /* no op */) { /* * All non-basic code points < n have been handled already. * Find the next larger one: */ for(m=0x7fffffff, j=0; j<srcCPCount; ++j) { q=cpBuffer[j]&0x7fffffff; /* remove case flag from the sign bit */ if(n<=q && q<m) { m=q; } } /* * Increase delta enough to advance the decoder's * <n,i> state to <m,0>, but guard against overflow: */ if(m-n>(0x7fffffff-MAX_CP_COUNT-delta)/(handledCPCount+1)) { *pErrorCode=U_INTERNAL_PROGRAM_ERROR; return 0; } delta+=(m-n)*(handledCPCount+1); n=m; /* Encode a sequence of same code points n */ for(j=0; j<srcCPCount; ++j) { q=cpBuffer[j]&0x7fffffff; /* remove case flag from the sign bit */ if(q<n) { ++delta; } else if(q==n) { /* Represent delta as a generalized variable-length integer: */ for(q=delta, k=BASE; /* no condition */; k+=BASE) { /** RAM: comment out the old code for conformance with draft-ietf-idn-punycode-03.txt t=k-bias; if(t<TMIN) { t=TMIN; } else if(t>TMAX) { t=TMAX; } */ t=k-bias; if(t<TMIN) { t=TMIN; } else if(k>=(bias+TMAX)) { t=TMAX; } if(q<t) { break; } if(destLength<destCapacity) { dest[destLength]=digitToBasic(t+(q-t)%(BASE-t), 0); } ++destLength; q=(q-t)/(BASE-t); } if(destLength<destCapacity) { dest[destLength]=digitToBasic(q, (UBool)(cpBuffer[j]<0)); } ++destLength; bias=adaptBias(delta, handledCPCount+1, (UBool)(handledCPCount==basicLength)); delta=0; ++handledCPCount; } } ++delta; ++n; } return u_terminateUChars(dest, destCapacity, destLength, pErrorCode); }