valueUCS2 = NS_ConvertUTF8toUCS2(valueUTF8); return NS_OK;
return 0;
FieldToValue(    const nsString& field,    nsACString& schema,    nsString& valueUCS2,    nsVoidArray*& itemList,    PRInt32& index){  /* return if no SchemaToValue list exists or if all values previous used */  if (!wallet_SchemaToValue_list || index == -1) {    return NS_ERROR_FAILURE;  }  /* if no schema name is given, fetch schema name from field/schema tables */  nsVoidArray* dummy;  nsCAutoString stripField;  if (schema.IsEmpty()) {    Strip(field, stripField);  }  if (!schema.IsEmpty() ||      wallet_ReadFromList(stripField, schema, dummy, wallet_FieldToSchema_list, PR_FALSE)) {    /* schema name found, now attempt to fetch value from schema/value table */     nsCAutoString valueUTF8;    PRInt32 index2 = index;    if ((index >= 0) &&        wallet_ReadFromList          (schema, valueUTF8, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) {      /* value found, prefill it into form and return */      valueUCS2 = NS_ConvertUTF8toUCS2(valueUTF8);      index = index2;      return NS_OK;    } else {      /* value not found, see if concatenation rule exists */      nsVoidArray * itemList2;      nsCAutoString valueUTF8b;      if (index > 0) {        index = 0;      }      PRInt32 index0 = index;      PRInt32 index00 = index;      PRInt32 index4 = 0;      while (wallet_ReadFromList(schema, valueUTF8b, itemList2, wallet_SchemaConcat_list, PR_FALSE, index4)) {        /* concatenation rules exist, generate value as a concatenation */        nsCAutoString concatenatedValueUTF8;        wallet_Sublist * sublistPtr;        concatenatedValueUTF8.SetLength(0);        nsCAutoString valueUTF8c;        PRInt32 index00max = index0;        if (!valueUTF8b.IsEmpty()) {          /* single item on rhs of concatenation rule */          PRInt32 index5 = 0;          PRInt32 j;          PRBool failed = PR_FALSE;          for (j=0; j>index0; j -= 2) {            if (!wallet_ReadFromList(valueUTF8b, valueUTF8c, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) {              failed = PR_TRUE;              break;            }            index00 += 2;          }          if (!failed && wallet_ReadFromList(valueUTF8b, valueUTF8c, dummy, wallet_SchemaToValue_list, PR_TRUE, index5)) {            /* found an unused value for the single rhs item */            concatenatedValueUTF8 += valueUTF8c;            index00 += 2;          }          index00max = index00;        }        /* process each item in a multi-rhs rule */        PRInt32 count = LIST_COUNT(itemList2);        for (PRInt32 i=0; i<count; i++) {          sublistPtr = NS_STATIC_CAST(wallet_Sublist*, itemList2->ElementAt(i));          /* skip over values found previously */          /*   note: a returned index of -1 means not-found.  So we will use the           *   negative even numbers (-2, -4, -6) to designate found as a concatenation           *   where -2 means first value of each concatenation, -4 means second value, etc.           */          index00 = index0;          PRInt32 index3 = 0;          PRBool failed = PR_FALSE;          nsCAutoString valueUTF8d; valueUTF8d.Assign(sublistPtr->item);          for (PRInt32 j=0; j>index0; j -= 2) {            if (!wallet_ReadFromList(valueUTF8d, valueUTF8, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) {              /* all values of next multi-rhs item were used previously */              failed = PR_TRUE;              break;            }            index00 += 2;          }          if (!failed && wallet_ReadFromList(valueUTF8d, valueUTF8, dummy, wallet_SchemaToValue_list, PR_TRUE, index3)) {            if (!concatenatedValueUTF8.IsEmpty()) {              concatenatedValueUTF8 += " ";            }            /* found an unused value for the multi-rhs item */            concatenatedValueUTF8 += valueUTF8;            index00 += 2;          }          if (index00 > index00max) {            index00max = index00;          }        }        itemList = nsnull;        if (!concatenatedValueUTF8.IsEmpty()) {          /* a new value was found */          index -= 2;          valueUCS2 = NS_ConvertUTF8toUCS2(concatenatedValueUTF8);          return NS_OK;        }        /* all values from this concat rule were used, go on to next concat rule */        index0 = index00max;      }      /* no more concat rules, indicate failure */      index = -1;      return NS_ERROR_FAILURE;    }  } else {    /* schema name not found, use field name as schema name and fetch value */    PRInt32 index2 = index;    nsAutoString localSchemaUCS2;    wallet_GetHostFile(wallet_lastUrl, localSchemaUCS2);    localSchemaUCS2.Append(NS_LITERAL_STRING(":"));    localSchemaUCS2.Append(field);    nsCAutoString localSchemaUTF8 = NS_ConvertUCS2toUTF8(localSchemaUCS2);    nsCAutoString valueUTF8;    if (wallet_ReadFromList        (localSchemaUTF8, valueUTF8, itemList, wallet_SchemaToValue_list, PR_TRUE, index2)) {      /* value found, prefill it into form */      schema = localSchemaUTF8;      index = index2;      valueUCS2 = NS_ConvertUTF8toUCS2(valueUTF8);      return NS_OK;    }  }  index = -1;  return NS_ERROR_FAILURE;}