Ejemplo n.º 1
0
//---------------------------------------------------------------------------
intptr_t TInteractiveCustomCommand::PatternLen(const UnicodeString & Command, intptr_t Index)
{
  intptr_t Len = 0;
  switch (Command[Index + 1])
  {
    case L'?':
      {
        const wchar_t * Ptr = Command.c_str() + Index - 1;
        const wchar_t * PatternEnd = wcschr(Ptr + 1, L'!');
        if (PatternEnd == nullptr)
        {
          throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, Command[Index + 1], Index));
        }
        Len = PatternEnd - Ptr + 1;
      }
      break;

    case L'`':
      {
        const wchar_t * Ptr = Command.c_str() + Index - 1;
        const wchar_t * PatternEnd = wcschr(Ptr + 2, L'`');
        if (PatternEnd == nullptr)
        {
          throw Exception(FMTLOAD(CUSTOM_COMMAND_UNTERMINATED, Command[Index + 1], Index));
        }
        Len = PatternEnd - Ptr + 1;
      }
      break;

    default:
      Len = FChildCustomCommand->PatternLen(Command, Index);
      break;
  }
  return Len;
}
Ejemplo n.º 2
0
BOOST_FIXTURE_TEST_CASE(test14, base_fixture_t)
{
  {
    UnicodeString str = ::StringReplace(L"AA", L"A", L"B", TReplaceFlags() << rfReplaceAll);
    BOOST_CHECK_EQUAL(W2MB(str.c_str()).c_str(), "BB");
  }
  {
    UnicodeString str = ::AnsiReplaceStr(L"AA", L"A", L"B");
    BOOST_CHECK_EQUAL(W2MB(str.c_str()).c_str(), "BB");
  }
  {
    UnicodeString str = L"ABC";
    BOOST_CHECK_EQUAL(::Pos(str, L"DEF"), 0);
    BOOST_CHECK_EQUAL(::Pos(str, L"AB"), 1);
    BOOST_CHECK_EQUAL(::Pos(str, L"BC"), 2);
    BOOST_CHECK_EQUAL(::AnsiPos(str, 'D'), 0);
    BOOST_CHECK_EQUAL(::AnsiPos(str, 'A'), 1);
    BOOST_CHECK_EQUAL(::AnsiPos(str, 'B'), 2);
  }
  {
    UnicodeString str = ::LowerCase(L"AA");
    BOOST_CHECK_EQUAL(W2MB(str.c_str()).c_str(), "aa");
  }
  {
    UnicodeString str = ::UpperCase(L"aa");
    BOOST_CHECK_EQUAL(W2MB(str.c_str()).c_str(), "AA");
  }
  {
    UnicodeString str = ::Trim(L" aa ");
    BOOST_CHECK_EQUAL(W2MB(str.c_str()).c_str(), "aa");
  }
}
Ejemplo n.º 3
0
UnicodeString TStrings::GetTextStr() const
{
  UnicodeString Result;
  intptr_t Count = GetCount();
  intptr_t Size = 0;
  UnicodeString LB = sLineBreak;
  for (intptr_t I = 0; I < Count; I++)
  {
    Size += GetString(I).Length() + LB.Length();
  }
  Result.SetLength(Size);
  wchar_t * P = const_cast<wchar_t *>(Result.c_str());
  for (intptr_t I = 0; I < Count; I++)
  {
    UnicodeString S = GetString(I);
    intptr_t L = S.Length() * sizeof(wchar_t);
    if (L != 0)
    {
      memmove(P, S.c_str(), L);
      P += S.Length();
    }
    L = LB.Length() * sizeof(wchar_t);
    if (L != 0)
    {
      memmove(P, LB.c_str(), L);
      P += LB.Length();
    }
  }
  return Result;
}
Ejemplo n.º 4
0
void TStrings::SetTextStr(const UnicodeString & Text)
{
  BeginUpdate();
  SCOPE_EXIT
  {
    EndUpdate();
  };
  {
    Clear();
    const wchar_t * P = Text.c_str();
    if (P != nullptr)
    {
      while (*P != 0x00)
      {
        const wchar_t * Start = P;
        while (!((*P == 0x00) || (*P == 0x0A) || (*P == 0x0D)))
        {
          P++;
        }
        UnicodeString S;
        S.SetLength(P - Start);
        memmove(const_cast<wchar_t *>(S.c_str()), Start, (P - Start) * sizeof(wchar_t));
        Add(S);
        if (*P == 0x0D) { P++; }
        if (*P == 0x0A) { P++; }
      }
    }
  }
}
Ejemplo n.º 5
0
bool TRegistry::OpenKey(const UnicodeString & Key, bool CanCreate)
{
  bool Result = false;
  UnicodeString S = Key;
  bool Relative = Classes::IsRelative(S);

  // if (!Relative) S.erase(0, 1); // Delete(S, 1, 1);
  HKEY TempKey = 0;
  if (!CanCreate || S.IsEmpty())
  {
    Result = RegOpenKeyEx(GetBaseKey(Relative), S.c_str(), 0,
                          FAccess, &TempKey) == ERROR_SUCCESS;
  }
  else
  {
    Result = RegCreateKeyEx(GetBaseKey(Relative), S.c_str(), 0, nullptr,
                            REG_OPTION_NON_VOLATILE, FAccess, nullptr, &TempKey, nullptr) == ERROR_SUCCESS;
  }
  if (Result)
  {
    if ((GetCurrentKey() != 0) && Relative)
    {
      S = FCurrentPath + L'\\' + S;
    }
    ChangeKey(TempKey, S);
  }
  return Result;
}
Ejemplo n.º 6
0
UnicodeString Format(const wchar_t * Format, va_list Args)
{
  UnicodeString Result;
  if (Format && *Format)
  {
    intptr_t Len = _vscwprintf(Format, Args);
    Result.SetLength(Len + 1);
    // vswprintf(Buf, Len + 1, Format, args);
    vswprintf(const_cast<wchar_t *>(Result.c_str()), Len + 1, Format, Args);
  }
  return Result.c_str();
}
Ejemplo n.º 7
0
BOOST_FIXTURE_TEST_CASE(test21, base_fixture_t)
{
  BOOST_TEST_MESSAGE("RAND_MAX = " << RAND_MAX);
  for (int i = 0; i < 10; i++)
  {
    BOOST_TEST_MESSAGE("rand() = " << rand());
    BOOST_TEST_MESSAGE("random(256) = " << random(256));
  }
  UnicodeString enc = ::EncryptPassword(L"1234ABC", L"234556");
  BOOST_TEST_MESSAGE("enc = " << W2MB(enc.c_str()).c_str());
  UnicodeString dec = ::DecryptPassword(enc, L"234556");
  BOOST_TEST_MESSAGE("dec = " << W2MB(dec.c_str()).c_str());
  BOOST_CHECK(dec == L"1234ABC");
}
Ejemplo n.º 8
0
UnicodeString ItemsFormatString(const UnicodeString & SingleItemFormat,
  const UnicodeString & MultiItemsFormat, intptr_t Count, const UnicodeString & FirstItem)
{
  UnicodeString Result;
  if (Count == 1)
  {
    Result = FORMAT(SingleItemFormat.c_str(), FirstItem.c_str());
  }
  else
  {
    Result = FORMAT(MultiItemsFormat.c_str(), Count);
  }
  return Result;
}
Ejemplo n.º 9
0
UnicodeString ExpandFileName(const UnicodeString & FileName)
{
  UnicodeString Result;
  UnicodeString Buf(MAX_PATH, 0);
  intptr_t Size = GetFullPathNameW(FileName.c_str(), static_cast<DWORD>(Buf.Length() - 1),
    reinterpret_cast<LPWSTR>(const_cast<wchar_t *>(Buf.c_str())), nullptr);
  if (Size > Buf.Length())
  {
    Buf.SetLength(Size);
    Size = ::GetFullPathNameW(FileName.c_str(), static_cast<DWORD>(Buf.Length() - 1),
      reinterpret_cast<LPWSTR>(const_cast<wchar_t *>(Buf.c_str())), nullptr);
  }
  return UnicodeString(Buf.c_str(), Size);
}
Ejemplo n.º 10
0
//---------------------------------------------------------------------------
void __fastcall TMediaDlgBox::GridSetEditText(TObject *Sender, int ACol,
	int ARow, const UnicodeString Value)
{
	double	d;

	if( Grid->EditorMode == TRUE ) return;
	if( ARow ){
		ARow--;
		switch(ACol){
			case 1:		// DIE(導)
				if( Calc(d, AnsiString(Value).c_str()) == TRUE){
					lenv.rel[ARow] = d;
					GridNewLine(ARow);
				}
				break;
			case 2:		// COND(誘電)
				if( Calc(d, AnsiString(Value).c_str()) == TRUE){
					lenv.cond[ARow] = d/1000.0;
					GridNewLine(ARow);
				}
				break;
			case 3:		// XorR(m)
				if( *Value.c_str() ){
					if( Calc(d, AnsiString(Value).c_str()) == TRUE){
						lenv.intval[ARow] = d;
						GridNewLine(ARow);
					}
				}
				else if( ARow >= (lenv.mmax - 1) ){
					lenv.intval[ARow] = NULLV;
					GridNewLine(ARow);
				}
				break;
			case 4:		// H(m)
				if( *Value.c_str() ){
					if( Calc(d, AnsiString(Value).c_str()) == TRUE){
						lenv.height[ARow] = d;
						GridNewLine(ARow);
					}
				}
				else if( ARow >= (lenv.mmax - 1) ){
					lenv.height[ARow] = NULLV;
					GridNewLine(ARow);
				}
				break;
		}
	}
}
Ejemplo n.º 11
0
static void tokenize(const UnicodeString & str, rde::vector<UnicodeString> & tokens,
  const UnicodeString & delimiters = L" ", const bool trimEmpty = false)
{
  intptr_t lastPos = 0;
  while (true)
  {
    intptr_t pos = str.FindFirstOf(delimiters.c_str(), lastPos);
    if (pos == NPOS)
    {
       pos = str.Length();

       if (pos != lastPos || !trimEmpty)
       {
         tokens.push_back(
           UnicodeString(str.data() + lastPos, pos - lastPos));
       }
       break;
    }
    else
    {
      if (pos != lastPos || !trimEmpty)
      {
        tokens.push_back(
          UnicodeString(str.data() + lastPos, pos - lastPos));
      }
    }

    lastPos = pos + 1;
  }
}
Ejemplo n.º 12
0
BOOST_FIXTURE_TEST_CASE(test19, base_fixture_t)
{
  UnicodeString ProgramsFolder;
  ::SpecialFolderLocation(CSIDL_PROGRAM_FILES, ProgramsFolder);
  BOOST_TEST_MESSAGE("ProgramsFolder = " << W2MB(ProgramsFolder.c_str()).c_str());
  BOOST_CHECK(ProgramsFolder.Length() > 0);
}
Ejemplo n.º 13
0
bool __fastcall TVersionInfo::QueryValue(const UnicodeString& SubBlock, LPVOID& Buffer,
  unsigned int& BufferLength) const
{
  assert(FFileVersionInfoData != NULL);

  return VerQueryValue(FFileVersionInfoData, SubBlock.c_str(), &Buffer, &BufferLength);
}
Ejemplo n.º 14
0
//---------------------------------------------------------------------
void TCopyParamList::ValidateName(const UnicodeString & Name)
{
  if (Name.LastDelimiter(FInvalidChars) > 0)
  {
    throw Exception(FMTLOAD(ITEM_NAME_INVALID, Name.c_str(), FInvalidChars.c_str()));
  }
}
Ejemplo n.º 15
0
//---------------------------------------------------------------------------
static bool __fastcall GetResource(
  const UnicodeString ResName, void *& Content, unsigned long & Size)
{
  HRSRC Resource = FindResourceEx(HInstance, RT_RCDATA, ResName.c_str(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
  bool Result = (Resource != NULL);
  if (Result)
  {
    Size = SizeofResource(HInstance, Resource);
    if (!Size)
    {
      throw Exception(FORMAT(L"Cannot get size of resource %s", (ResName)));
    }

    Content = LoadResource(HInstance, Resource);
    if (!Content)
    {
      throw Exception(FORMAT(L"Cannot read resource %s", (ResName)));
    }

    Content = LockResource(Content);
    if (!Content)
    {
      throw Exception(FORMAT(L"Cannot lock resource %s", (ResName)));
    }
  }

  return Result;
}
Ejemplo n.º 16
0
UnicodeString UpperCase(const UnicodeString & Str)
{
  std::wstring Result(Str.c_str(), Str.Length());
  // Result.SetLength(Str.Length());
  std::transform(Result.begin(), Result.end(), Result.begin(), ::toupper);
  return Result;
}
Ejemplo n.º 17
0
UnicodeString ExpandEnvVars(const UnicodeString & Str)
{
  wchar_t buf[MAX_PATH];
  intptr_t size = ExpandEnvironmentStringsW(Str.c_str(), buf, static_cast<DWORD>(MAX_PATH - 1));
  UnicodeString Result = UnicodeString(buf, size - 1);
  return Result;
}
Ejemplo n.º 18
0
bool TOptions::SwitchValue(const UnicodeString & Switch, bool Default, bool DefaultOnNonExistence)
{
  bool Result = false;
  int64_t IntValue = 0;
  UnicodeString Value;
  if (!FindSwitch(Switch, Value))
  {
    Result = DefaultOnNonExistence;
  }
  else if (Value.IsEmpty())
  {
    Result = Default;
  }
  else if (::SameText(Value, L"on"))
  {
    Result = true;
  }
  else if (::SameText(Value, L"off"))
  {
    Result = false;
  }
  else if (::TryStrToInt(Value, IntValue))
  {
    Result = (IntValue != 0);
  }
  else
  {
    throw Exception(FMTLOAD(URL_OPTION_BOOL_VALUE_ERROR, Value.c_str()));
  }
  return Result;
}
Ejemplo n.º 19
0
void TCopyParamList::ValidateName(const UnicodeString & Name)
{
  if (Name.LastDelimiter(CONST_INVALID_CHARS) > 0)
  {
    throw Exception(FMTLOAD(ITEM_NAME_INVALID, Name.c_str(), CONST_INVALID_CHARS));
  }
}
Ejemplo n.º 20
0
UnicodeString Format(const wchar_t * Format, ...)
{
  va_list Args;
  va_start(Args, Format);
  UnicodeString Result = ::Format(Format, Args);
  va_end(Args);
  return Result.c_str();
}
Ejemplo n.º 21
0
void DoTraceFmt(const wchar_t * SourceFile, const wchar_t * Func,
                uintptr_t Line, const wchar_t * AFormat, va_list Args)
{
    DebugAssert(IsTracing);

    UnicodeString Message = FormatV(AFormat, Args);
    DoTrace(SourceFile, Func, Line, Message.c_str());
}
Ejemplo n.º 22
0
bool TRegistryStorage::Copy(TRegistryStorage * Storage)
{
  TRegistry * Registry = Storage->FRegistry;
  bool Result = true;
  std::unique_ptr<TStrings> Names(new TStringList());
  try__finally
  {
    rde::vector<uint8_t> Buffer(1024);
    Registry->GetValueNames(Names.get());
    intptr_t Index = 0;
    while ((Index < Names->GetCount()) && Result)
    {
      UnicodeString Name = MungeStr(Names->GetString(Index), GetForceAnsi());
      DWORD Size = static_cast<DWORD>(Buffer.size());
      DWORD Type;
      int RegResult = 0;
      do
      {
        RegResult = ::RegQueryValueEx(Registry->GetCurrentKey(), Name.c_str(), nullptr,
          &Type, &Buffer[0], &Size);
        if (RegResult == ERROR_MORE_DATA)
        {
          Buffer.resize(Size);
        }
      }
      while (RegResult == ERROR_MORE_DATA);

      Result = (RegResult == ERROR_SUCCESS);
      if (Result)
      {
        RegResult = ::RegSetValueEx(FRegistry->GetCurrentKey(), Name.c_str(), 0, Type,
          &Buffer[0], Size);
        Result = (RegResult == ERROR_SUCCESS);
      }

      ++Index;
    }
  }
  __finally
  {
/*
    delete Names;
*/
  };
  return Result;
}
Ejemplo n.º 23
0
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
FILE * OpenFile(const UnicodeString & LogFileName, TSessionData * SessionData, bool Append, UnicodeString & NewFileName)
{
  FILE * Result;
  UnicodeString ANewFileName = StripPathQuotes(GetExpandedLogFileName(LogFileName, SessionData));
  // Result = _wfopen(ANewFileName.c_str(), (Append ? L"a" : L"w"));
  Result = _fsopen(W2MB(ANewFileName.c_str()).c_str(),
    Append ? "a" : "w", SH_DENYWR); // _SH_DENYNO); // 
  if (Result != nullptr)
  {
    setvbuf(Result, nullptr, _IONBF, BUFSIZ);
    NewFileName = ANewFileName;
  }
  else
  {
    throw Exception(FMTLOAD(LOG_OPENERROR, ANewFileName.c_str()));
  }
  return Result;
}
Ejemplo n.º 24
0
HKEY TRegistry::GetKey(const UnicodeString & Key)
{
  UnicodeString S = Key;
  bool Relative = Classes::IsRelative(S);
  // if not Relative then Delete(S, 1, 1);
  HKEY Result = 0;
  RegOpenKeyEx(GetBaseKey(Relative), S.c_str(), 0, FAccess, &Result);
  return Result;
}
Ejemplo n.º 25
0
//---------------------------------------------------------------------------
UnicodeString __fastcall TConfiguration::BannerHash(const UnicodeString & Banner)
{
  RawByteString Result;
  Result.SetLength(16);
  md5checksum(
    reinterpret_cast<const char*>(Banner.c_str()), Banner.Length() * sizeof(wchar_t),
    (unsigned char*)Result.c_str());
  return BytesToHex(Result);
}
Ejemplo n.º 26
0
UnicodeString TConfiguration::BannerHash(const UnicodeString & Banner) const
{
  RawByteString Result;
  Result.SetLength(16);
  md5checksum(
    reinterpret_cast<const char *>(Banner.c_str()), static_cast<int>(Banner.Length() * sizeof(wchar_t)),
    reinterpret_cast<uint8_t *>(const_cast<char *>(Result.c_str())));
  return BytesToHex(Result);
}
Ejemplo n.º 27
0
uintptr_t GetSpeedLimit(const UnicodeString & Text)
{
  uintptr_t Speed = 0;
  if (!TryGetSpeedLimit(Text, Speed))
  {
    throw Exception(FMTLOAD(SPEED_INVALID, Text.c_str()));
  }
  return Speed;
}
Ejemplo n.º 28
0
//---------------------------------------------------------------------------
void __fastcall OpenBrowser(UnicodeString URL)
{
  UnicodeString HomePageUrl = LoadStr(HOMEPAGE_URL);
  if (SameText(URL.SubString(1, HomePageUrl.Length()), HomePageUrl))
  {
    URL = CampaignUrl(URL);
  }
  ShellExecute(Application->Handle, L"open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
Ejemplo n.º 29
0
bool TRegistry::GetDataInfo(const UnicodeString & ValueName, TRegDataInfo & Value) const
{
  DWORD DataType;
  ClearStruct(Value);
  bool Result = (RegQueryValueEx(GetCurrentKey(), ValueName.c_str(), nullptr, &DataType, nullptr,
                                 &Value.DataSize) == ERROR_SUCCESS);
  Value.RegData = DataTypeToRegData(DataType);
  return Result;
}
Ejemplo n.º 30
0
UnicodeString GetPersonalFolder()
{
  UnicodeString Result;
  SpecialFolderLocation(CSIDL_PERSONAL, Result);

  if (IsWine())
  {
    UnicodeString WineHostHome;
    int Len = ::GetEnvironmentVariable(L"WINE_HOST_HOME", nullptr, 0);
    if (Len > 0)
    {
      WineHostHome.SetLength(Len - 1);
      ::GetEnvironmentVariable(L"WINE_HOST_HOME", const_cast<LPWSTR>(WineHostHome.c_str()), Len);
    }
    if (!WineHostHome.IsEmpty())
    {
      UnicodeString WineHome = L"Z:" + core::ToUnixPath(WineHostHome);
      if (::DirectoryExists(WineHome))
      {
        Result = WineHome;
      }
    }
    else
    {
      // Should we use WinAPI GetUserName() instead?
      UnicodeString UserName;
      int Len = ::GetEnvironmentVariable(L"USERNAME", nullptr, 0);
      if (Len > 0)
      {
        UserName.SetLength(Len - 1);
        ::GetEnvironmentVariable(L"USERNAME", const_cast<LPWSTR>(UserName.c_str()), Len);
      }
      if (!UserName.IsEmpty())
      {
        UnicodeString WineHome = L"Z:\\home\\" + UserName;
        if (::DirectoryExists(WineHome))
        {
          Result = WineHome;
        }
      }
    }
  }
  return Result;
}