예제 #1
0
err_t Application::setWorkingDirectory(const StringW& dir)
{
  StringW dirW;
  FOG_RETURN_ON_ERROR(WinUtil::makeWinPath(dirW, dir));

  if (SetCurrentDirectoryW(reinterpret_cast<const wchar_t*>(dirW.getData())) == 0)
    return ERR_OK;
  else
    return OSUtil::getErrFromOSLastError();
}
예제 #2
0
// Object name can contain characters [A-Z], [a-z], '-', '_', [0-9]. Numbers
// are not allowed for the first character.
static err_t Object_validatePropertyName(const StringW& name)
{
  const CharW* data = name.getData();
  size_t length = name.getLength();

  if (length == 0)
    return ERR_PROPERTY_INVALID;

  CharW c = data[0];
  if (!(c.isAsciiLetter() || c == CharW('_') || c == CharW('-')))
    return ERR_PROPERTY_INVALID;

  for (size_t i = 1; i < length; i++)
  {
    if (!(c.isAsciiNumlet() || c == CharW('_') || c == CharW('-')))
      return ERR_PROPERTY_INVALID;
  }

  return ERR_OK;
}
예제 #3
0
static void Application_parseWinCmdLine(const StringW& cmdLine, List<StringW>& dst)
{
  const CharW* cur = cmdLine.getData();
  const CharW* end = cur + cmdLine.getLength();

  const CharW* mark;
  CharW quote;
  bool isEscaped;
  size_t len;

  for (;;)
  {
    // Skip spaces.
    for (;;)
    {
      if (cur == end) goto end;
      if (cur->isSpace()) cur++;
      else break;
    }

    // Zero character means end.
    if (cur->isNull())
      goto end;

    // Parse quote character (if it's here).
    mark = cur;
    quote = 0;

    if (cur[0] == CharW('\"') ||
        cur[0] == CharW('\'') )
    {
      quote = cur[0];
    }
    cur++;

    // Parse argument
    isEscaped = false;

    for (;;)
    {
      if (cur == end) goto parsed;

      CharW c = cur[0];
      if (c.isNull()) goto parsed;
      if (c.isSpace() && quote.isNull()) goto parsed;

      // Quotes.
      if (c == quote)
      {
        cur++;
        goto parsed;
      }

      // Escape sequence.
      if (c == CharW('\\'))
      {
        if (cur < end - 1 && (cur[1] == CharW('\"') ||
                              cur[1] == CharW('\'') ||
                              cur[1] == CharW(' ')) )
        {
          cur++;
          isEscaped = true;
        }
      }

      cur++;
    }

parsed:
    len = (size_t)(cur - mark);
    if (quote.isNull())
    {
      mark++;
      len--;
      if (len && mark[len-1] == quote) len--;
    }

    {
      StringW arg(mark, len);
      
      if (isEscaped)
        Application_unescapeArgument(arg);
      
      dst.append(arg);
    }
  }

end:
  return;
}