示例#1
0
/*
 * find() finds the offset where the string is stored, returns -1 if not found.
 * It only compares raw byte values, there is no Unicode normalization handling.
 * If ppBufMB is non-null you must delete[] it (Only valid when m_wide is false)!
*/
unsigned int ExeHeadStringList::find(const TCHAR *str, WORD codepage, bool processed, char**ppBufMB) const
{
  if (m_wide && *str)
  {
    WCToUTF16LEHlpr cnv;
    if (!cnv.Create(str)) return -1;
    unsigned int pos = find(cnv.Get(),StrLenUTF16(cnv.Get()),codepage,processed,ppBufMB);
    cnv.Destroy();
    return pos;
  }
  else
  {
    return find(str,_tcslen(str),codepage,processed,ppBufMB);
  }
}
示例#2
0
int ExeHeadStringList::add(const TCHAR *str, WORD codepage, bool processed)
{
  char *p = (char*) m_gr.get();
  if (!p)
  {
    if (!*str) return 0; // Delay allocating the empty string
    char *&zero = p, cb = 1 + !!m_wide;
    unsigned int pos = m_gr.add(&zero,cb);
    assert(0 == pos);
  }

  char *bufMB = 0;
  unsigned int pos = find(str,codepage,processed,m_wide ? 0 : &bufMB);
  if ((unsigned)-1 != pos)
  {
    delete[] bufMB;
    return pos;
  }

  if (m_wide)
  {
    WCToUTF16LEHlpr cnv;
    if (!cnv.Create(str)) throw std::bad_alloc();
    pos = m_gr.add(cnv.Get(),cnv.GetSize()) / WIDEDIV;
    cnv.Destroy();
  }
  else
  {
    unsigned int cbMB = strlen(bufMB) + 1;
    pos = m_gr.add(bufMB,cbMB);
    delete[] bufMB;
  }
  return pos;
}
static void SaveVersionHeader(GrowBuf &strm, WORD wLength, WORD wValueLength, WORD wType, const wchar_t *key, void *value)
{
  WCToUTF16LEHlpr cnv;
  if (!cnv.Create(key)) throw std::runtime_error("Unicode conversion failed");
  SaveVersionHeaderUTF16LE(strm, wLength, wValueLength, wType, cnv.Get(), value);
  cnv.Destroy();
}