// Convert the list of words in iwords to the same capitalization aWord and // return them in owords. NS_IMETHODIMP mozEnglishWordUtils::FromRootForm(const char16_t *aWord, const char16_t **iwords, uint32_t icount, char16_t ***owords, uint32_t *ocount) { nsAutoString word(aWord); nsresult rv = NS_OK; int32_t length; char16_t **tmpPtr = (char16_t **)moz_xmalloc(sizeof(char16_t *)*icount); if (!tmpPtr) return NS_ERROR_OUT_OF_MEMORY; mozEnglishWordUtils::myspCapitalization ct = captype(word); for(uint32_t i = 0; i < icount; ++i) { length = NS_strlen(iwords[i]); tmpPtr[i] = (char16_t *) moz_xmalloc(sizeof(char16_t) * (length + 1)); if (MOZ_UNLIKELY(!tmpPtr[i])) { NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, tmpPtr); return NS_ERROR_OUT_OF_MEMORY; } memcpy(tmpPtr[i], iwords[i], (length + 1) * sizeof(char16_t)); nsAutoString capTest(tmpPtr[i]); mozEnglishWordUtils::myspCapitalization newCt=captype(capTest); if(newCt == NoCap){ switch(ct) { case HuhCap: case NoCap: break; case AllCap: ToUpperCase(tmpPtr[i],tmpPtr[i],length); rv = NS_OK; break; case InitCap: ToUpperCase(tmpPtr[i],tmpPtr[i],1); rv = NS_OK; break; default: rv = NS_ERROR_FAILURE; // should never get here; break; } } } if (NS_SUCCEEDED(rv)){ *owords = tmpPtr; *ocount = icount; } return rv; }
// Convert the list of words in iwords to the same capitalization aWord and // return them in owords. NS_IMETHODIMP mozEnglishWordUtils::FromRootForm(const PRUnichar *aWord, const PRUnichar **iwords, PRUint32 icount, PRUnichar ***owords, PRUint32 *ocount) { nsAutoString word(aWord); nsresult rv = NS_OK; PRInt32 length; PRUnichar **tmpPtr = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *)*icount); if (!tmpPtr) return NS_ERROR_OUT_OF_MEMORY; mozEnglishWordUtils::myspCapitalization ct = captype(word); for(PRUint32 i = 0; i < icount; ++i) { length = nsCRT::strlen(iwords[i]); tmpPtr[i] = (PRUnichar *) nsMemory::Alloc(sizeof(PRUnichar) * (length + 1)); if (NS_UNLIKELY(!tmpPtr[i])) { NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(i, tmpPtr); return NS_ERROR_OUT_OF_MEMORY; } memcpy(tmpPtr[i], iwords[i], (length + 1) * sizeof(PRUnichar)); nsAutoString capTest(tmpPtr[i]); mozEnglishWordUtils::myspCapitalization newCt=captype(capTest); if(newCt == NoCap){ switch(ct) { case HuhCap: case NoCap: break; case AllCap: rv = mCaseConv->ToUpper(tmpPtr[i],tmpPtr[i],length); break; case InitCap: rv = mCaseConv->ToUpper(tmpPtr[i],tmpPtr[i],1); break; default: rv = NS_ERROR_FAILURE; // should never get here; break; } } } if (NS_SUCCEEDED(rv)){ *owords = tmpPtr; *ocount = icount; } return rv; }
int main(int argc, char const *argv[]) { if (argc < 2) exit(EXIT_FAILURE); count = atoi(argv[1]); if (count < 1) exit(EXIT_FAILURE); result = (char*)calloc(maxStrLen, sizeof(char)); elements = (char*)calloc(count, sizeof(char)); elements[0] = 'a'; emptyString = (char*)calloc(maxStrLen, sizeof(char)); int i = 0; int j = 0; int k = 0; int l = 0; int m = 0; int n = 0; for(i = 1; i < count; i++){ elements[i] = elements[i-1] + 1; } int combinations = 0; combinations = pow(2, count) - 1; char **topology = (char**)malloc(sizeof(char*)*(combinations + 1)); for(i = 0; i < combinations; i++){ topology[i] = (char*)calloc(maxStrLen, sizeof(char)); } P = (char**)malloc(sizeof(char*)*combinations); for(i = 0; i < combinations; i++){ P[i] = (char*)calloc(maxStrLen, sizeof(char)); } for(i = 1; i <= combinations; i++){ //combination iteration for(j = 0; j < count; j++){ // character iteration if (getChar(i, j)){ P[i-1][l++] = elements[j]; } } l = 0; } int combinationsTopology = 0; combinationsTopology = pow(2, combinations - 1) - 1; k = 2; topology[0][0] = '0'; memcpy(topology[1], P[combinations-1], maxByteLen); for(i = 0; i < combinationsTopology; i++){ for(j = 0; j < combinations; j++){ if (getChar(i, j)){ memcpy(topology[k++], P[j], maxByteLen); } } if (cupTest(topology, k) && capTest(topology, k)){ printf("%3d %3d: {", i, ++m); for(n = 0; n < k; n++){ printf("{%s}, ", topology[n]); } printf("\b\b}\n"); } for (k--; k >=2; k--){ memcpy(topology[k], emptyString, maxByteLen); } k++; // = 2 // assert(false); } return 0; }