示例#1
0
文件: NsisIn.cpp 项目: Dabil/puNES
// Based on Dave Laundon's simplified process_string
AString GetNsisString(const AString &s)
{
  AString res;
  for (int i = 0; i < s.Length();)
  {
    unsigned char nVarIdx = s[i++];
    if (nVarIdx > NS_CODES_START && i + 2 <= s.Length())
    {
      int nData = s[i++] & 0x7F;
      unsigned char c1 = s[i++];
      nData |= (((int)(c1 & 0x7F)) << 7);

      if (nVarIdx == NS_SHELL_CODE)
        res += GetShellString(c1);
      else if (nVarIdx == NS_VAR_CODE)
        res += GetVar(nData);
      else if (nVarIdx == NS_LANG_CODE)
        res += "NS_LANG_CODE";
    }
    else if (nVarIdx == NS_SKIP_CODE)
    {
      if (i < s.Length())
        res += s[i++];
    }
    else // Normal char
      res += (char)nVarIdx;
  }
  return res;
}
示例#2
0
bool ClipboardSetText(HWND owner, const UString &s)
{
  CClipboard clipboard;
  if (!clipboard.Open(owner))
    return false;
#ifdef _WIN32
  if (!::EmptyClipboard())
    return false;

  bool res;
  res = ClipboardSetData(CF_UNICODETEXT, (const wchar_t *)s, (s.Length() + 1) * sizeof(wchar_t));
  #ifndef _UNICODE
  AString a;
  a = UnicodeStringToMultiByte(s, CP_ACP);
  res |=  ClipboardSetData(CF_TEXT, (const char *)a, (a.Length() + 1) * sizeof(char));
  a = UnicodeStringToMultiByte(s, CP_OEMCP);
  res |=  ClipboardSetData(CF_OEMTEXT, (const char *)a, (a.Length() + 1) * sizeof(char));
  #endif
  return res;
#else
  wxTheClipboard->Clear();
  // This data objects are held by the clipboard,
  // so do not delete them in the app.
  wxString ws(s);
  wxTheClipboard->SetData( new wxTextDataObject(ws) );
  return true;
#endif
}
示例#3
0
static void CopyStrLimited(char *dest, const AString &src, int len)
{
  len--;
  if (src.Length() < len)
    len = src.Length();
  memcpy(dest, src, sizeof(dest[0]) * len);
  dest[len] = 0;
}
示例#4
0
    /** ********************************************************************************************
     * Specialization of template method
     * \ref aworx::lib::strings::ApplyTo "ApplyTo" for applicable type \b std::string.
     * See \ref aworx::lib::strings::ApplyTo "ApplyTo" for more information.
     * @param  target The AString to append \p src to.
     * @param  logger The logger to apply.
     * @return The length of the given string \p src which was appended to \p target.
     **********************************************************************************************/
    template<>   inline   int         ApplyTo <const lox::core::Logger&>( AString& target, const lox::core::Logger& logger )
    {
        int origTargetLength= target.Length();
        target << logger.GetName();
        if ( !logger.GetName().Equals( logger.GetTypeName() ) )
            target << " (" << logger.GetTypeName() << ")";

        return (int) target.Length() - origTargetLength;
    }
示例#5
0
static void  test_AString()
{
   AString a;

   a = "abc";
   assert(MyStringCompare(&a[0],"abc") == 0);
   assert(a.Length() == 3);

   a = GetAnsiString(L"abc");
   assert(MyStringCompare(&a[0],"abc") == 0);
   assert(a.Length() == 3);
}
示例#6
0
bool HasTailSlash(const AString &name, UINT codePage)
{
  if (name.IsEmpty())
    return false;
  LPCSTR prev =
  #ifdef _WIN32
    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);
  #else
    (LPCSTR)(name) + (name.Length() - 1);
  #endif
  return (*prev == '/');
}
示例#7
0
文件: TarOut.cpp 项目: BIAINC/7Zip
static bool MakeOctalString12(char *s, UInt64 value)
{
  AString tempString  = MakeOctalString(value);
  const int kMaxSize = 12;
  if (tempString.Length() > kMaxSize)
    return false;
  int numSpaces = kMaxSize - tempString.Length();
  for(int i = 0; i < numSpaces; i++)
    s[i] = ' ';
  memmove(s + numSpaces, (const char *)tempString, tempString.Length());
  return true;
}
示例#8
0
文件: TarOut.cpp 项目: BIAINC/7Zip
static bool MakeOctalString8(char *s, UInt32 value)
{
  AString tempString = MakeOctalString(value);

  const int kMaxSize = 8;
  if (tempString.Length() >= kMaxSize)
    return false;
  int numSpaces = kMaxSize - (tempString.Length() + 1);
  for(int i = 0; i < numSpaces; i++)
    s[i] = ' ';
  MyStringCopy(s + numSpaces, (const char *)tempString);
  return true;
}
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
{
  UString resultString;
  if (!srcString.IsEmpty())
  {
    int numChars = MultiByteToWideChar(codePage, 0, srcString,
      srcString.Length(), resultString.GetBuffer(srcString.Length()),
      srcString.Length() + 1);
    if (numChars == 0)
      throw 282228;
    resultString.ReleaseBuffer(numChars);
  }
  return resultString;
}
示例#10
0
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
{
  UString resultString;
  for (int i = 0; i < srcString.Length(); i++)
    resultString += wchar_t(srcString[i]);
  return resultString;
}
示例#11
0
文件: Plugin.cpp 项目: BIAINC/7Zip
static AString GetNameOfProp2(PROPID propID, const wchar_t *name)
{
  AString s = GetNameOfProp(propID, name);
  if (s.Length() > (kInfoPanelLineSize - 1))
    s = s.Left(kInfoPanelLineSize - 1);
  return s;
}
示例#12
0
	double atof_test(const AString& string, bool& success)
	{
		char* endptr = 0;
		double result = strtod(string.Buffer(), &endptr);
		success = endptr == string.Buffer() + string.Length();
		return result;
	}
示例#13
0
	vuint64_t atou64_test(const AString& string, bool& success)
	{
		char* endptr = 0;
		vuint64_t result = _strtoui64(string.Buffer(), &endptr, 10);
		success = endptr == string.Buffer() + string.Length() && u64toa(result) == string;
		return result;
	}
示例#14
0
	vint atoi_test(const AString& string, bool& success)
	{
		char* endptr = 0;
		vint result = strtol(string.Buffer(), &endptr, 10);
		success = endptr == string.Buffer() + string.Length() && itoa(result) == string;
		return result;
	}
示例#15
0
void ACanvasSkia::DrawText(int x1,int y1,const AString& sText)
{
	//_clip();
	_SetPaint_Font();

	int nFontSize = GetFont()->GetSize();
	y1 += nFontSize;
	//y1 -= 2;//微调 fix me later
	//AString str;
	//str = sText;
// 	AMemory ms;
// 	ms.SetSize( ::WideCharToMultiByte(CP_UTF8,0,sText.Text(),sText.Length(),NULL,0,NULL,NULL) +1 );
// 	char* buf = (char *)ms.GetData();
// 	::WideCharToMultiByte(CP_UTF8,0,sText.Text(),sText.Length(),buf,ms.GetSize()-1,NULL,NULL);
// 	buf[ms.GetSize()-1] = 0;
	const char* sz = (char *)sText.Text();// buf;//str.ConvertTo();
	int iLen = sText.Length()*sizeof(ACHAR);// sz ? strlen(sz) : 0 );

	m_Paint.setTextSize(SkIntToScalar(nFontSize));
	//m_Paint.setSubpixelText(false);
	//m_Paint.setLinearText(true);
	//m_Paint.setHinting(SkPaint::kFull_Hinting);
	m_pCanvas->drawText(sz,iLen,SkIntToScalar(x1),SkIntToScalar(y1),m_Paint);
	
// 	SkPoint pts[1000];
// 	SkScalar xpos = x1;
// 	//SkASSERT(length <= SK_ARRAY_COUNT(pts));
// 	for (size_t i = 0; i < iLen; i++) {
// 		pts[i].set(xpos, y1), xpos += nFontSize;
// 	}
// 	m_pCanvas->drawPosText(sz, iLen, pts, m_Paint);

	Reset();
}
示例#16
0
bool HasTailSlash(const AString &name, UINT codePage)
{
  if (name.IsEmpty())
    return false;
  LPCSTR prev =
  #if defined(_WIN32) && !defined(UNDER_CE)
  #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
    (LPCSTR)(name) + (name.Length() - 1);
  #else
    CharPrevExA((WORD)codePage, name, &name[name.Length()], 0);
  #endif
  #else
    (LPCSTR)(name) + (name.Length() - 1);
  #endif
  return (*prev == '/');
}
示例#17
0
文件: TarOut.cpp 项目: BIAINC/7Zip
static bool CopyString(char *dest, const AString &src, int maxSize)
{
  if (src.Length() >= maxSize)
    return false;
  MyStringCopy(dest, (const char *)src);
  return true;
}
示例#18
0
文件: Main.cpp 项目: liao0818/nsis7z
static void PrintString(CStdOutStream &stdStream, const AString &s, int size)
{
  int len = s.Length();
  stdStream << s;
  for (int i = len; i < size; i++)
    stdStream << ' ';
}
示例#19
0
void AClipboard::SetText(const AString& sText,bool bUnicode /*=true */ )
{
	if(::OpenClipboard(NULL))
	{
		::EmptyClipboard();
		HGLOBAL clipbuffer;
		char *buffer;
		if( bUnicode )
		{
			clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, (sText.Length()+1)*2);
			buffer = (char *)::GlobalLock(clipbuffer);
			wcscpy((wchar_t*)buffer,sText.Text());
			::GlobalUnlock(clipbuffer);
			::SetClipboardData(CF_UNICODETEXT, clipbuffer);
		}
		else
		{
			AString str2;
			str2 = sText;
			const UACHAR* sz = str2.ConvertTo();
			clipbuffer = ::GlobalAlloc(GMEM_DDESHARE, strlen(sz)+1);
			buffer = (char *)::GlobalLock(clipbuffer);
			strcpy(buffer,sz);
			::GlobalUnlock(clipbuffer);
			::SetClipboardData(CF_TEXT, clipbuffer);
		}
		::CloseClipboard();
	}
}
示例#20
0
文件: Plugin.cpp 项目: BIAINC/7Zip
static AString PropToString2(const NCOM::CPropVariant &prop, PROPID propID)
{
  AString s = PropToString(prop, propID);
  if (s.Length() > (kInfoPanelLineSize - 1))
    s = s.Left(kInfoPanelLineSize - 1);
  return s;
}
示例#21
0
void  testMaxOSX_stringConvert()
{
/*
                         0xE8, // latin small letter e with grave
                         0xE9, // latin small letter e with acute
                         L'a',
                         0xE0, // latin small letter a with grave
                         0x20AC, // euro sign
*/
   struct
   {
     char astr [256];
     wchar_t ustr [256];
   }
   tab [] =
   {
      {
      //   'a' , 'e with acute'       , 'e with grave'     ,  'a with grave'    ,  'u with grave'    ,  'b' , '.'  ,  't' , 'x'  , 't'  
         { 0x61,  0x65,  0xcc,  0x81  ,  0x65,  0xcc,  0x80,  0x61,  0xcc,  0x80,  0x75,  0xcc,  0x80,  0x62,  0x2e,  0x74,  0x78, 0x74,  0 },
         { 0x61,  0xe9,                  0xe8,                0xe0,                0xf9,                0x62,  0x2e,  0x74,  0x78, 0x74, 0 }
      },
      {
      //   'a' , 'euro sign'        ,  'b' , '.'  ,  't' , 'x'  , 't'  , '\n' 
         { 0x61,  0xe2,  0x82,  0xac,  0x62,  0x2e,  0x74,  0x78,  0x74,  0x0a, 0 },
         { 0x61,  0x20AC,              0x62,  0x2e,  0x74,  0x78,  0x74,  0x0a, 0 }  
      },
      {
         { 0 },
         { 0 }
      }
   };

   int i;

   printf("testMaxOSX_stringConvert : \n");

   i = 0;
   while (tab[i].astr[0])
   {
     printf("  %s\n",tab[i].astr);

     UString ustr = GetUnicodeString(tab[i].astr);

     // dumpWStr("1",&ustr[0]);

     assert(MyStringCompare(&ustr[0],tab[i].ustr) == 0);
     assert(ustr.Length() == wcslen(tab[i].ustr) );


     AString astr = GetAnsiString(ustr);
     assert(MyStringCompare(&astr[0],tab[i].astr) == 0);
     assert(astr.Length() == strlen(tab[i].astr) );

     i++;
   }
}
示例#22
0
	bool Semaphore::Create(vint initialCount, vint maxCount, const WString& name)
	{
		if (internalData) return false;
		if (initialCount > maxCount) return false;

		internalData = new SemaphoreData;
#if defined(__APPLE__)
        
		AString auuid;
		if(name.Length() == 0)
		{
			CFUUIDRef cfuuid = CFUUIDCreate(kCFAllocatorDefault);
			CFStringRef cfstr = CFUUIDCreateString(kCFAllocatorDefault, cfuuid);
			auuid = CFStringGetCStringPtr(cfstr, kCFStringEncodingASCII);

			CFRelease(cfstr);
			CFRelease(cfuuid);
		}
		auuid = auuid.Insert(0, "/");
		// OSX SEM_NAME_LENGTH = 31
		if(auuid.Length() >= 30)
			auuid = auuid.Sub(0, 30);
        
		if ((internalData->semNamed = sem_open(auuid.Buffer(), O_CREAT, O_RDWR, initialCount)) == SEM_FAILED)
		{
			delete internalData;
			internalData = 0;
			return false;
		}
        
#else
		if (name == L"")
		{
			if(sem_init(&internalData->semUnnamed, 0, (int)initialCount) == -1)
			{
				delete internalData;
				internalData = 0;
				return false;
			}
		}
        	else
        	{
			AString astr = wtoa(name);
            
			if ((internalData->semNamed = sem_open(astr.Buffer(), O_CREAT, 0777, initialCount)) == SEM_FAILED)
			{
				delete internalData;
				internalData = 0;
				return false;
			}
		}
#endif

		Release(initialCount);
		return true;
	}
示例#23
0
文件: Clipboard.cpp 项目: bks/qz7
bool ClipboardSetText(HWND owner, const UString &s)
{
  CClipboard clipboard;
  if (!clipboard.Open(owner))
    return false;
  if (!::EmptyClipboard())
    return false;

  bool res;
  res = ClipboardSetData(CF_UNICODETEXT, (const wchar_t *)s, (s.Length() + 1) * sizeof(wchar_t));
  #ifndef _UNICODE
  AString a;
  a = UnicodeStringToMultiByte(s, CP_ACP);
  res |=  ClipboardSetData(CF_TEXT, (const char *)a, (a.Length() + 1) * sizeof(char));
  a = UnicodeStringToMultiByte(s, CP_OEMCP);
  res |=  ClipboardSetData(CF_OEMTEXT, (const char *)a, (a.Length() + 1) * sizeof(char));
  #endif
  return res;
}
示例#24
0
static bool ParseSha1(const CXmlItem &item, const char *name, Byte *digest)
{
  int index = item.FindSubTag(name);
  if (index  < 0)
    return false;
  const CXmlItem &checkItem = item.SubItems[index];
  AString style = checkItem.GetPropertyValue("style");
  if (style == "SHA1")
  {
    AString s = checkItem.GetSubString();
    if (s.Length() != 40)
      return false;
    for (int i = 0; i < s.Length(); i += 2)
    {
      Byte b0, b1;
      if (!HexToByte(s[i], b0) || !HexToByte(s[i + 1], b1))
        return false;
      digest[i / 2] = (b0 << 4) | b1;
    }
    return true;
  }
  return false;
}
示例#25
0
UString MultiByteToUnicodeString(const AString &srcString, UINT codePage)
{
  UString resultString;
  for (int i = 0; i < srcString.Length(); i++)
    resultString += wchar_t(srcString[i]);
  /*
  if (!srcString.IsEmpty())
  {
    int numChars = mbstowcs(resultString.GetBuffer(srcString.Length()), srcString, srcString.Length() + 1);
    if (numChars < 0) throw "Your environment does not support UNICODE";
    resultString.ReleaseBuffer(numChars);
  }
  */
  return resultString;
}
示例#26
0
文件: FSFolder.cpp 项目: bks/qz7
bool CFSFolder::SaveComments()
{
  NIO::COutFile file;
  if (!file.Create(_path + kDescriptionFileName, true))
    return false;
  UString unicodeString;
  _comments.SaveToString(unicodeString);
  AString utfString;
  ConvertUnicodeToUTF8(unicodeString, utfString);
  UInt32 processedSize;
  if (!IsAscii(unicodeString))
  {
    Byte bom [] = { 0xEF, 0xBB, 0xBF, 0x0D, 0x0A };
    file.Write(bom , sizeof(bom), processedSize);
  }
  file.Write(utfString, utfString.Length(), processedSize);
  _commentsAreLoaded = false;
  return true;
}
示例#27
0
int ACanvasSkia::MeasurePosition(const AString& sText,int iPos)//根据位置找到所在字符串的下标
{
	_SetPaint_Font();
	int iLen = sText.Length();
	ACHAR* s = (ACHAR*)sText.Text();
	int x=0;
	int i=0;
	for(i=0;i<iLen;i++)
	{
		int y = m_Paint.measureText(s,(i+1)*sizeof(ACHAR));
		if( iPos >= x && iPos <= y ) 
		{
			int delta = (y-x)/2;
			if( iPos < x+delta ) return i;
			else return i+1;
		}
		x = y;
	}
	return i;
}
示例#28
0
void GCanvas::DrawText(const ARect& r,const AString& sText,TTextAlign ta)
{
	Flush();

	UINT uFormat=DT_SINGLELINE;
	switch(ta)
	{
	case taLeftTop: uFormat |= DT_LEFT | DT_TOP; break;
	case taCenterTop:uFormat |= DT_CENTER | DT_TOP;break;
	case taRightTop:uFormat |= DT_RIGHT | DT_TOP; break;
	case taLeftMiddle:uFormat |= DT_LEFT | DT_VCENTER;break;
	case taCenterMiddle : uFormat |= DT_CENTER|DT_VCENTER;break;
	case taRightMiddle: uFormat |= DT_RIGHT | DT_VCENTER;break;
	case taLeftBottom: uFormat |= DT_LEFT | DT_BOTTOM; break;
	case taCenterBottom: uFormat |= DT_CENTER | DT_BOTTOM; break;
	case taRightBottom: uFormat |= DT_RIGHT | DT_BOTTOM;break;
	default:break;
	}
	::DrawText(m_hDC,sText.Text(),sText.Length(),(LPRECT)&r,uFormat);
}
示例#29
0
static UInt64 ParseTime(const CXmlItem &item, const char *name)
{
  AString s = item.GetSubStringForTag(name);
  if (s.Length() < 20)
    return 0;
  const char *p = s;
  if (p[ 4] != '-' || p[ 7] != '-' || p[10] != 'T' ||
      p[13] != ':' || p[16] != ':' || p[19] != 'Z')
    return 0;
  UInt32 year, month, day, hour, min, sec;
  if (!ParseNumber(p,      4, year )) return 0;
  if (!ParseNumber(p + 5,  2, month)) return 0;
  if (!ParseNumber(p + 8,  2, day  )) return 0;
  if (!ParseNumber(p + 11, 2, hour )) return 0;
  if (!ParseNumber(p + 14, 2, min  )) return 0;
  if (!ParseNumber(p + 17, 2, sec  )) return 0;

  UInt64 numSecs;
  if (!NWindows::NTime::GetSecondsSince1601(year, month, day, hour, min, sec, numSecs))
    return 0;
  return numSecs * 10000000;
}
示例#30
0
static void SplitString(const AString &srcString, AStringVector &destStrings)
{
  destStrings.Clear();
  AString string;
  int len = srcString.Length();
  if (len == 0)
    return;
  for (int i = 0; i < len; i++)
  {
    char c = srcString[i];
    if (c == '\n')
    {
      if (!string.IsEmpty())
      {
        destStrings.Add(string);
        string.Empty();
      }
    }
    else
      string += c;
  }
  if (!string.IsEmpty())
    destStrings.Add(string);
}