void nsOEStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle) { PRUnichar *ptrv = GetStringByID( stringID, pBundle); result = ptrv; FreeString( ptrv); }
void nsEudoraStringBundle::GetStringByID(int32_t stringID, nsString& result) { PRUnichar *ptrv = GetStringByID(stringID); result = ptrv; FreeString(ptrv); }
Bool LoadBlakodString(FILE *f,int len_str,int string_id) { string_node *snod; /* note: new_str is not a null-terminated string */ if (AllocateString() != string_id) { eprintf("LoadString didn't make string id %i\n",string_id); return False; } snod = GetStringByID(string_id); if (len_str != 0) { snod->data = (char *)AllocateMemory(MALLOC_ID_STRING,len_str+1); if (!fread(snod->data, 1, len_str, f)) return False; snod->data[len_str] = '\0'; } else { snod->data = NULL; } snod->len_data = len_str; return True; }
void MoveStringNode(int dest_id,int source_id) /* for garbage collection */ { string_node *source,*dest; source = GetStringByID(source_id); if (source == NULL) { eprintf("MoveString can't find source %i, total death end game\n", source_id); FlushDefaultChannels(); return; } dest = GetStringByID(dest_id); if (dest == NULL) { eprintf("MoveString can't find dest %i, total death end game\n", dest_id); FlushDefaultChannels(); return; } /* we're guaranteed dest_id <= source_id. We don't need to do anything * if they're the same. */ if (dest_id == source_id) return; if (dest->data != NULL) FreeMemory(MALLOC_ID_STRING,dest->data,dest->len_data+1); dest->data = source->data; dest->len_data = source->len_data; source->data = NULL; source->len_data = 0; }
int CreateStringWithLen(char *buf,int len) { int string_id; string_node *snod; /* note: new_str is NOT null-terminated */ string_id = AllocateString(); snod = GetStringByID(string_id); snod->data = (char *)AllocateMemory(MALLOC_ID_STRING,len+1); memcpy(snod->data,buf,len); snod->len_data = len; snod->data[snod->len_data] = '\0'; return string_id; }
nsString nsEudoraStringBundle::FormatString(int32_t stringID, ...) { // Yeah, I know. This causes an extra string buffer allocation, but there's no guarantee // that nsString's free and nsTextFormatter::smprintf_free deallocate memory the same way. nsAutoString format; GetStringByID(stringID, format); va_list args; va_start(args, stringID); PRUnichar *pText = nsTextFormatter::vsmprintf(format.get(), args); va_end(args); nsString result(pText); nsTextFormatter::smprintf_free(pText); return result; }
void FreeString(int string_id) /* for garbage collection */ { string_node *snod; snod = GetStringByID(string_id); if (snod == NULL) { eprintf("FreeString can't find %i\n",string_id); return; } if (snod->data != NULL) { FreeMemory(MALLOC_ID_STRING,snod->data,snod->len_data+1); } else { /* happens when blank string saved, loaded, then garbage collected */ /* eprintf("FreeString can't free NULL string %i\n",string_id); */ } snod->data = NULL; snod->len_data = 0; }
void nsImportStringBundle::GetStringByID(PRInt32 aStringID, nsIStringBundle *aBundle, nsString &aResult) { aResult.Adopt(GetStringByID(aStringID, aBundle)); }
void nsOEStringBundle::GetStringByID(int32_t stringID, nsString& result) { char16_t *ptrv = GetStringByID(stringID); result.Adopt(ptrv); }
void AddBlakodToPacket(val_type obj_size,val_type obj_data) { int num_bytes; char byte1; short byte2; int byte4; string_node *snod; resource_node *r; val_type temp_val; if (obj_size.v.tag != TAG_INT) { bprintf("AddBlakodToPacket looking for int, # of bytes, got %i,%i\n", obj_size.v.tag,obj_size.v.data); return; } num_bytes = obj_size.v.data; if (obj_data.v.tag == TAG_NIL) bprintf("AddBlakodToPacket looking for value, got NIL\n"); /* dprintf("Send %i bytes from %i,%i\n",obj_size.data,obj_data.v.tag,obj_data.v.data); */ switch (obj_data.v.tag) { case TAG_STRING : snod = GetStringByID(obj_data.v.data); if (snod == NULL) { bprintf("AddBlakodToPacket can't find string id %i\n",obj_data.v.data); break; } AddStringToPacket(snod->len_data,snod->data); break; case TAG_TEMP_STRING : snod = GetTempString(); AddStringToPacket(snod->len_data,snod->data); break; default : switch (num_bytes) { case 1 : byte1 = (char) obj_data.v.data; AddByteToPacket(byte1); break; case 2 : byte2 = (short) obj_data.v.data; AddShortToPacket(byte2); break; case 4 : byte4 = (int) obj_data.v.data; AddIntToPacket(byte4); break; case NUMBER_OBJECT : temp_val.int_val = obj_data.int_val; temp_val.v.tag = CLIENT_TAG_NUMBER; byte4 = temp_val.int_val; AddIntToPacket(byte4); break; case STRING_RESOURCE : if (obj_data.v.tag != TAG_RESOURCE) { bprintf("AddBlakodToPacket can't send %i,%i as a resource/string\n", obj_data.v.tag,obj_data.v.data); return; } r = GetResourceByID(obj_data.v.data); if (r == NULL) { bprintf("AddBlakodToPacket can't find resource %i as a resource/string\n", obj_data.v.data); return; } AddStringToPacket(strlen(r->resource_val[0]),r->resource_val[0]); break; default : bprintf("AddBlakodToPacket can't send %i bytes\n",num_bytes); break; } } }