Ejemplo n.º 1
0
std::wstring Dictionary::Lookup(const std::string& section, const std::string& key) const
{
  DataType::const_iterator it = data.find(KeyType(section, key));
  if (it == data.end())
    return L"### MISSING STRING [" + ToUtf16String(section) + L", " + ToUtf16String(key) + L"] ###";

  return it->second;
}
Ejemplo n.º 2
0
bool CPluginFilter::ShouldBlock(const std::wstring& src, AdblockPlus::FilterEngine::ContentType contentType, const std::wstring& domain, bool addDebug) const
{
  std::wstring srcTrimmed = TrimString(src);

  // We should not block the empty string, so all filtering does not make sense
  // Therefore we just return
  if (srcTrimmed.empty())
  {
    return false;
  }

  CPluginSettings* settings = CPluginSettings::GetInstance();

  CPluginClient* client = CPluginClient::GetInstance();
  bool result = client->Matches(srcTrimmed, contentType, domain);

#ifdef ENABLE_DEBUG_RESULT
  if (addDebug)
  {
    std::wstring type = ToUtf16String(AdblockPlus::FilterEngine::ContentTypeToString(contentType));
    if (result)
    {
      CPluginDebug::DebugResultBlocking(type, srcTrimmed, domain);
    }
    else
    {
      CPluginDebug::DebugResultIgnoring(type, srcTrimmed, domain);
    }
  }
#endif
  return result;
}
std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::wstring& defaultValue)
{
  DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_PREF << ToUtf8String(name);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return defaultValue;
  bool success;
  response >> success;
  if (success)
  {
    std::string value;
    response >> value;
    DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
    return ToUtf16String(value);
  }
  else
  {
Ejemplo n.º 4
0
bool Dictionary::ReadDictionary(const std::wstring& basePath, const std::wstring& locale)
{
  std::ifstream stream(basePath + locale + L".ini");
  if (stream.fail())
    return false;

  std::string section;
  while (!stream.eof())
  {
    std::string line;
    std::getline(stream, line);
    if (stream.fail())
      return false;

    line = ::TrimString(line);
    if (line.size() >= 2 && line[0] == '[' && line[line.size() - 1] == ']')
    {
      // Section header
      section = line.substr(1, line.size() - 2);
    }
    else if (line.size() >= 1 && line[0] == '#')
    {
      // Comment
      continue;
    }
    else
    {
      // Value
      size_t pos = line.find('=');
      if (pos != std::string::npos)
      {
        std::string key = ::TrimString(line.substr(0, pos));
        std::string value = ::TrimString(line.substr(pos + 1));
        data[KeyType(section, key)] = ToUtf16String(value);
      }
    }
  }
  return true;
}