Example #1
0
//---------------------------------------------------------------------------
UnicodeString DelimitFileNameMask(const UnicodeString & Mask)
{
  UnicodeString Result = Mask;
  for (intptr_t I = 1; I <= Result.Length(); I++)
  {
    if (wcschr(L"\\*?", Result[I]) != nullptr)
    {
      Result.Insert(L"\\", I);
      I++;
    }
  }
  return Result;
}
Example #2
0
//---------------------------------------------------------------------------
UnicodeString IntToHex(uintptr_t Int, uintptr_t MinChars)
{
  UnicodeString Result;
  Result.sprintf(L"%X", Int);
  intptr_t Pad = MinChars - Result.Length();
  if (Pad > 0)
  {
    for (intptr_t I = 0; I < Pad; I++)
    {
      Result.Insert(L'0', 1);
    }
  }
  return Result;
}
Example #3
0
//---------------------------------------------------------------------------
UnicodeString TFileMasks::ComposeMaskStr(
  TStrings * MasksStr, bool Directory)
{
  UnicodeString Result;
  UnicodeString ResultNoDirMask;
  for (intptr_t I = 0; I < MasksStr->GetCount(); ++I)
  {
    UnicodeString Str = MasksStr->GetString(I).Trim();
    if (!Str.IsEmpty())
    {
      for (intptr_t P = 1; P <= Str.Length(); P++)
      {
        if (Str.IsDelimiter(AllFileMasksDelimiters, P))
        {
          Str.Insert(Str[P], P);
          P++;
        }
      }

      UnicodeString StrNoDirMask;
      if (Directory)
      {
        StrNoDirMask = Str;
        Str = MakeDirectoryMask(Str);
      }
      else
      {
        while (Str.IsDelimiter(DirectoryMaskDelimiters, Str.Length()))
        {
          Str.SetLength(Str.Length() - 1);
        }
        StrNoDirMask = Str;
      }

      AddToList(Result, Str, FileMasksDelimiterStr);
      AddToList(ResultNoDirMask, StrNoDirMask, FileMasksDelimiterStr);
    }
  }

  // For directories, the above will add slash ay the end of masks,
  // breaking size and time masks and thus circumverting their validation.
  // This performes as hoc validation to cover the scenario.
  // For files this makes no difference, but no harm either
  TFileMasks Temp(Directory ? 1 : 0);
  Temp = ResultNoDirMask;

  return Result;
}
Example #4
0
static UnicodeString DoXmlEscape(const UnicodeString & Str, bool NewLine)
{
  UnicodeString Result = Str;
  for (intptr_t Index = 1; Index <= Result.Length(); ++Index)
  {
    const wchar_t * Repl = nullptr;
    switch (Result[Index])
    {
      case L'&':
        Repl = L"amp;";
        break;

      case L'>':
        Repl = L"gt;";
        break;

      case L'<':
        Repl = L"lt;";
        break;

      case L'"':
        Repl = L"quot;";
        break;

      case L'\n':
        if (NewLine)
        {
          Repl = L"#10;";
        }
        break;

      case L'\r':
        Result.Delete(Index, 1);
        Index--;
        break;
    }

    if (Repl != nullptr)
    {
      Result[Index] = L'&';
      Result.Insert(Repl, Index + 1);
      Index += wcslen(Repl);
    }
  }
  return Result;
}
static UnicodeString DoXmlEscape(UnicodeString AStr, bool NewLine)
{
  UnicodeString Str = AStr;
  for (intptr_t Index = 1; Index <= Str.Length(); ++Index)
  {
    const wchar_t *Repl = nullptr;
    switch (Str[Index])
    {
    case L'&':
      Repl = L"amp;";
      break;

    case L'>':
      Repl = L"gt;";
      break;

    case L'<':
      Repl = L"lt;";
      break;

    case L'"':
      Repl = L"quot;";
      break;

    case L'\n':
      if (NewLine)
      {
        Repl = L"#10;";
      }
      break;

    case L'\r':
      Str.Delete(Index, 1);
      --Index;
      break;
    }

    if (Repl != nullptr)
    {
      Str[Index] = L'&';
      Str.Insert(Repl, Index + 1);
      Index += nb::StrLength(Repl);
    }
  }
  return Str;
}
Example #6
0
//---------------------------------------------------------------------------
UnicodeString __fastcall DoXmlEscape(UnicodeString Str, bool NewLine)
{
  for (int i = 1; i <= Str.Length(); i++)
  {
    const wchar_t * Repl = NULL;
    switch (Str[i])
    {
      case L'&':
        Repl = L"amp;";
        break;

      case L'>':
        Repl = L"gt;";
        break;

      case L'<':
        Repl = L"lt;";
        break;

      case L'"':
        Repl = L"quot;";
        break;

      case L'\n':
        if (NewLine)
        {
          Repl = L"#10;";
        }
        break;

      case L'\r':
        Str.Delete(i, 1);
        i--;
        break;
    }

    if (Repl != NULL)
    {
      Str[i] = L'&';
      Str.Insert(Repl, i + 1);
      i += wcslen(Repl);
    }
  }
  return Str;
}