当前位置: 首页>>代码示例>>C++>>正文


C++ StringPiece::str方法代码示例

本文整理汇总了C++中StringPiece::str方法的典型用法代码示例。如果您正苦于以下问题:C++ StringPiece::str方法的具体用法?C++ StringPiece::str怎么用?C++ StringPiece::str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringPiece的用法示例。


在下文中一共展示了StringPiece::str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getXlogCategoryNameForFile

std::string getXlogCategoryNameForFile(StringPiece filename) {
  // Buck mangles the directory layout for header files.  Rather than including
  // them from their original location, it moves them into deep directories
  // inside buck-out, and includes them from there.
  //
  // If this path looks like a buck header directory, try to strip off the
  // buck-specific portion.
  if (filename.startsWith("buck-out/")) {
    filename = stripBuckOutPrefix(filename);
  }

  std::string categoryName = filename.str();

  // Translate slashes to dots, to turn the directory layout into
  // a category hierarchy.
  size_t lastDot = std::string::npos;
  for (size_t n = 0; n < categoryName.size(); ++n) {
    if (categoryName[n] == '/') {
      categoryName[n] = '.';
      lastDot = std::string::npos;
    } else if (categoryName[n] == '.') {
      lastDot = n;
    }
  }

  // Strip off the filename extension, if one was present.
  if (lastDot != std::string::npos) {
    categoryName.resize(lastDot);
  }
  return categoryName;
}
开发者ID:Orvid,项目名称:folly,代码行数:31,代码来源:xlog.cpp

示例2: pathBasename

 static StringPiece pathBasename(StringPiece path) {
   auto idx = path.rfind('/');
   if (idx == StringPiece::npos) {
     return path.str();
   }
   return path.subpiece(idx + 1);
 }
开发者ID:amin-jabri,项目名称:folly,代码行数:7,代码来源:LoggerTest.cpp

示例3: filePtr

std::shared_ptr<ElfFile> ElfCache::getFile(StringPiece p) {
  auto path = p.str();

  std::lock_guard<std::mutex> lock(mutex_);

  auto pos = files_.find(path);
  if (pos != files_.end()) {
    // Found, move to back (MRU)
    auto& entry = pos->second;
    lruList_.erase(lruList_.iterator_to(*entry));
    lruList_.push_back(*entry);
    return filePtr(entry);
  }

  auto entry = std::make_shared<Entry>();

  // No negative caching
  if (entry->file.openNoThrow(path.c_str()) == -1) {
    return nullptr;
  }

  if (files_.size() == capacity_) {
    // Evict LRU
    lruList_.pop_front();
  }

  files_.emplace(std::move(path), entry);
  lruList_.push_back(*entry);

  return filePtr(entry);
}
开发者ID:Psyduck43,项目名称:folly,代码行数:31,代码来源:ElfCache.cpp

示例4: filePtr

std::shared_ptr<ElfFile> ElfCache::getFile(StringPiece p) {
  std::lock_guard<std::mutex> lock(mutex_);

  auto pos = files_.find(p);
  if (pos != files_.end()) {
    // Found, move to back (MRU)
    auto& entry = pos->second;
    lruList_.erase(lruList_.iterator_to(*entry));
    lruList_.push_back(*entry);
    return filePtr(entry);
  }

  auto entry = std::make_shared<Entry>();
  entry->path = p.str();
  auto& path = entry->path;

  // No negative caching
  const char* msg = "";
  int r = entry->file.openNoThrow(path.c_str(), true, &msg);
  if (r != ElfFile::kSuccess) {
    return nullptr;
  }

  if (files_.size() == capacity_) {
    auto& e = lruList_.front();
    lruList_.pop_front();
    files_.erase(e.path);
  }

  files_.emplace(entry->path, entry);
  lruList_.push_back(*entry);

  return filePtr(entry);
}
开发者ID:15Koala,项目名称:folly,代码行数:34,代码来源:ElfCache.cpp

示例5: build

RocksHandles::RocksHandles(
    StringPiece dbPath,
    const Options& options,
    const std::vector<ColumnFamilyDescriptor>& columnDescriptors) {
  auto dbPathStr = dbPath.str();
  DB* dbRaw;
  std::vector<ColumnFamilyHandle*> columnHandles;

  // This will create any newly defined column families automatically,
  // so we needn't make any special migration steps here; just define
  // a new family and start to use it.
  // If we remove column families in the future this call will fail
  // and shout at us for not opening up the database with them defined.
  // We will need to do "something smarter" if we ever decide to perform
  // that kind of a migration.
  auto status =
      DB::Open(options, dbPathStr, columnDescriptors, &columnHandles, &dbRaw);
  if (!status.ok()) {
    XLOG(ERR) << "Error opening RocksDB storage at " << dbPathStr << ": "
              << status.ToString();
    throw RocksException::build(
        status, "error opening RocksDB storage at", dbPathStr);
  }

  db.reset(dbRaw);
  columns.reserve(columnHandles.size());
  for (auto h : columnHandles) {
    columns.emplace_back(h);
  }
}
开发者ID:facebookexperimental,项目名称:eden,代码行数:30,代码来源:RocksHandles.cpp

示例6: IPAddressFormatException

// public string constructor
IPAddressV6::IPAddressV6(StringPiece addr) {
    auto ip = addr.str();

    // Allow addresses surrounded in brackets
    if (ip.size() < 2) {
        throw IPAddressFormatException(
            to<std::string>("Invalid IPv6 address '", ip, "': address too short"));
    }
    if (ip.front() == '[' && ip.back() == ']') {
        ip = ip.substr(1, ip.size() - 2);
    }

    struct addrinfo* result;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET6;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_NUMERICHOST;
    if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) {
        struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr;
        addr_.in6Addr_ = ipAddr->sin6_addr;
        scope_ = ipAddr->sin6_scope_id;
        freeaddrinfo(result);
    } else {
        throw IPAddressFormatException(
            to<std::string>("Invalid IPv6 address '", ip, "'"));
    }
}
开发者ID:ChenXuJasper,项目名称:folly,代码行数:29,代码来源:IPAddressV6.cpp

示例7: IPAddressFormatException

// public string constructor
IPAddressV4::IPAddressV4(StringPiece addr)
  : addr_()
{
  auto ip = addr.str();
  if (inet_pton(AF_INET, ip.c_str(), &addr_.inAddr_) != 1) {
    throw IPAddressFormatException("Invalid IPv4 address '", addr, "'");
  }
}
开发者ID:HunterChen,项目名称:folly,代码行数:9,代码来源:IPAddressV4.cpp

示例8: expect

void expect(LineReader& lr, const char* expected) {
  StringPiece line;
  size_t expectedLen = strlen(expected);
  EXPECT_EQ(expectedLen != 0 ? LineReader::kReading : LineReader::kEof,
            lr.readLine(line));
  EXPECT_EQ(expectedLen, line.size());
  EXPECT_EQ(std::string(expected, expectedLen), line.str());
}
开发者ID:HunterChen,项目名称:folly,代码行数:8,代码来源:LineReaderTest.cpp

示例9: addFunction

void FunctionScheduler::addFunction(Function<void()>&& cb,
                                    milliseconds interval,
                                    StringPiece nameID,
                                    milliseconds startDelay) {
  addFunctionGenericDistribution(
      std::move(cb),
      ConstIntervalFunctor(interval),
      nameID.str(),
      to<std::string>(interval.count(), "ms"),
      startDelay);
}
开发者ID:1Hgm,项目名称:folly,代码行数:11,代码来源:FunctionScheduler.cpp

示例10: writeFileAtomic

void writeFileAtomic(
    StringPiece filename,
    iovec* iov,
    int count,
    mode_t permissions) {
  auto rc = writeFileAtomicNoThrow(filename, iov, count, permissions);
  if (rc != 0) {
    auto msg = std::string(__func__) + "() failed to update " + filename.str();
    throw std::system_error(rc, std::generic_category(), msg);
  }
}
开发者ID:SocialExplorerFork,项目名称:folly,代码行数:11,代码来源:FileUtil.cpp

示例11: addFunctionUniformDistribution

void FunctionScheduler::addFunctionUniformDistribution(
    Function<void()>&& cb,
    milliseconds minInterval,
    milliseconds maxInterval,
    StringPiece nameID,
    milliseconds startDelay) {
  addFunctionGenericDistribution(
      std::move(cb),
      UniformDistributionFunctor(minInterval, maxInterval),
      nameID.str(),
      to<std::string>(
          "[", minInterval.count(), " , ", maxInterval.count(), "] ms"),
      startDelay);
}
开发者ID:1Hgm,项目名称:folly,代码行数:14,代码来源:FunctionScheduler.cpp

示例12: stopCapture

void PktCaptureManager::stopCapture(StringPiece name) {
  std::lock_guard<std::mutex> g(mutex_);

  auto nameStr = name.str();
  auto it = activeCaptures_.find(nameStr);
  if (it == activeCaptures_.end()) {
    throw FbossError("no active capture found with name \"", name, "\"");
  }
  LOG(INFO) << "stopping packet capture \"" << name << "\"";
  it->second->stop();
  inactiveCaptures_[nameStr] = std::move(it->second);
  activeCaptures_.erase(it);
  capturesRunning_.store(!activeCaptures_.empty(), std::memory_order_release);
}
开发者ID:HengWang,项目名称:fboss,代码行数:14,代码来源:PktCaptureManager.cpp

示例13: IPAddressFormatException

// public string constructor
IPAddressV6::IPAddressV6(StringPiece addr) {
    auto ip = addr.str();

    // Allow addresses surrounded in brackets
    if (ip.size() < 2) {
        throw IPAddressFormatException("Invalid IPv6 address '", ip,
                                       "': address too short");
    }
    if (ip.front() == '[' && ip.back() == ']') {
        ip = ip.substr(1, ip.size() - 2);
    }

    if (inet_pton(AF_INET6, ip.c_str(), &addr_.in6Addr_) != 1) {
        throw IPAddressFormatException("Invalid IPv6 address '", ip, "'");
    }
}
开发者ID:hanzz2007,项目名称:folly,代码行数:17,代码来源:IPAddressV6.cpp

示例14: IPAddressFormatException

// public string constructor
IPAddress::IPAddress(StringPiece addr)
  : addr_()
  , family_(AF_UNSPEC)
{
  string ip = addr.str();  // inet_pton() needs NUL-terminated string
  auto throwFormatException = [&](const string& msg) {
    throw IPAddressFormatException(
        to<std::string>("Invalid IP '", ip, "': ", msg));
  };

  if (ip.size() < 2) {
    throwFormatException("address too short");
  }
  if (ip.front() == '[' && ip.back() == ']') {
    ip = ip.substr(1, ip.size() - 2);
  }

  // need to check for V4 address second, since IPv4-mapped IPv6 addresses may
  // contain a period
  if (ip.find(':') != string::npos) {
    struct addrinfo* result;
    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_INET6;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_NUMERICHOST;
    if (!getaddrinfo(ip.c_str(), nullptr, &hints, &result)) {
      struct sockaddr_in6* ipAddr = (struct sockaddr_in6*)result->ai_addr;
      addr_ = IPAddressV46(IPAddressV6(*ipAddr));
      family_ = AF_INET6;
      freeaddrinfo(result);
    } else {
      throwFormatException("getsockaddr failed for V6 address");
    }
  } else if (ip.find('.') != string::npos) {
    in_addr ipAddr;
    if (inet_pton(AF_INET, ip.c_str(), &ipAddr) != 1) {
      throwFormatException("inet_pton failed for V4 address");
    }
    addr_ = IPAddressV46(IPAddressV4(ipAddr));
    family_ = AF_INET;
  } else {
    throwFormatException("invalid address format");
  }
}
开发者ID:1Hgm,项目名称:folly,代码行数:46,代码来源:IPAddress.cpp

示例15: FbossError

unique_ptr<PktCapture> PktCaptureManager::forgetCapture(StringPiece name) {
  std::lock_guard<std::mutex> g(mutex_);
  auto nameStr = name.str();
  auto activeIt = activeCaptures_.find(nameStr);
  if (activeIt != activeCaptures_.end()) {
    LOG(INFO) << "stopping packet capture \"" << name << "\"";
    std::unique_ptr<PktCapture> capture = std::move(activeIt->second);
    activeCaptures_.erase(activeIt);
    capturesRunning_.store(!activeCaptures_.empty(),
                           std::memory_order_release);
    capture->stop();
    return capture;
  }

  auto inactiveIt = inactiveCaptures_.find(nameStr);
  if (inactiveIt != inactiveCaptures_.end()) {
    std::unique_ptr<PktCapture> capture = std::move(inactiveIt->second);
    inactiveCaptures_.erase(inactiveIt);
    return capture;
  }

  throw FbossError("no capture found with name \"", name, "\"");
}
开发者ID:HengWang,项目名称:fboss,代码行数:23,代码来源:PktCaptureManager.cpp


注:本文中的StringPiece::str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。