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


C++ Optional::IsNull方法代码示例

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


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

示例1: TestDict

 static void TestDict(DictPtr dict) {
   Optional<DictEntry> entry;
   entry = dict->MatchPrefix("BYVoid");
   AssertTrue(!entry.IsNull());
   AssertEquals("BYVoid", entry.Get().key);
   AssertEquals("byv", entry.Get().GetDefault());
   
   entry = dict->MatchPrefix("BYVoid123");
   AssertTrue(!entry.IsNull());
   AssertEquals("BYVoid", entry.Get().key);
   AssertEquals("byv", entry.Get().GetDefault());
   
   entry = dict->MatchPrefix(utf8("積羽沉舟"));
   AssertTrue(!entry.IsNull());
   AssertEquals(utf8("積羽沉舟"), entry.Get().key);
   AssertEquals(utf8("羣輕折軸"), entry.Get().GetDefault());
   
   entry = dict->MatchPrefix("Unknown");
   AssertTrue(entry.IsNull());
   
   const vector<DictEntry> matches = dict->MatchAllPrefixes(utf8("清華大學計算機系"));
   AssertEquals(3, matches.size());
   AssertEquals(utf8("清華大學"), matches.at(0).key);
   AssertEquals("TsinghuaUniversity", matches.at(0).GetDefault());
   AssertEquals(utf8("清華"), matches.at(1).key);
   AssertEquals("Tsinghua", matches.at(1).GetDefault());
   AssertEquals(utf8("清"), matches.at(2).key);
   AssertEquals("Tsing", matches.at(2).GetDefault());
 }
开发者ID:jy4618272,项目名称:OpenCC,代码行数:29,代码来源:DictTestUtils.hpp

示例2: clearBuffer

vector<string> MaxMatchSegmentation::Segment(const string& text) {
  vector<string> segments;
  vector<string> buffer;
  auto clearBuffer = [&segments, &buffer]() {
                       if (buffer.size() > 0) {
                         segments.push_back(UTF8Util::Join(buffer));
                         buffer.clear();
                       }
                     };
  for (const char* pstr = text.c_str(); *pstr != '\0';) {
    Optional<DictEntry> matched = dict->MatchPrefix(pstr);
    size_t matchedLength;
    if (matched.IsNull()) {
      matchedLength = UTF8Util::NextCharLength(pstr);
      buffer.push_back(UTF8Util::FromSubstr(pstr, matchedLength));
    } else {
      clearBuffer();
      matchedLength = matched.Get().key.length();
      segments.push_back(matched.Get().key);
    }
    pstr += matchedLength;
  }
  clearBuffer();
  return segments;
}
开发者ID:jy4618272,项目名称:OpenCC,代码行数:25,代码来源:MaxMatchSegmentation.cpp

示例3: main

int main(int argc, const char* argv[]) {
  try {
    TCLAP::CmdLine cmd("Open Chinese Convert (OpenCC) Command Line Tool",
                       ' ',
                       VERSION);
    CmdLineOutput cmdLineOutput;
    cmd.setOutput(&cmdLineOutput);

    TCLAP::ValueArg<string> configArg("c", "config",
                                      "Configuration file",
                                      false /* required */,
                                      "s2t.json" /* default */,
                                      "file" /* type */,
                                      cmd);
    TCLAP::ValueArg<string> outputArg("o", "output",
                                      "Write converted text to",
                                      false /* required */,
                                      "" /* default */,
                                      "file" /* type */,
                                      cmd);
    TCLAP::ValueArg<string> inputArg("i", "input",
                                     "Read original text from",
                                     false /* required */,
                                     "" /* default */,
                                     "file" /* type */,
                                     cmd);
    TCLAP::ValueArg<bool> noFlushArg("", "noflush",
                                     "Disable flush for every line",
                                     false /* required */,
                                     false /* default */,
                                     "bool" /* type */,
                                     cmd);
    cmd.parse(argc, argv);
    configFileName = configArg.getValue();
    noFlush = noFlushArg.getValue();
    if (inputArg.isSet()) {
      inputFileName = Optional<string>(inputArg.getValue());
    }
    if (outputArg.isSet()) {
      outputFileName = Optional<string>(outputArg.getValue());
      noFlush = true;
    }
    converter = config.NewFromFile(configFileName);
    bool lineByLine = inputFileName.IsNull();
    if (lineByLine) {
      ConvertLineByLine();
    } else {
      Convert();
    }
  } catch (TCLAP::ArgException& e) {
    std::cerr << "error: " << e.error()
        << " for arg " << e.argId() << std::endl;
  } catch (Exception& e) {
    std::cerr << e.what() << std::endl;
  }
  return 0;
}
开发者ID:DavidXZK,项目名称:OpenCC,代码行数:57,代码来源:CommandLine.cpp

示例4: BindNull

void SqlConnection::DataCommand::BindDouble(
    SqlConnection::ArgumentIndex position,
    const Optional<double> &value)
{
    if (value.IsNull())
        BindNull(position);
    else
        BindDouble(position, *value);
}
开发者ID:tizenorg,项目名称:platform.framework.web.wrt-commons,代码行数:9,代码来源:sql_connection.cpp

示例5: GetOutputStream

FILE* GetOutputStream() {
  if (outputFileName.IsNull()) {
    return stdout;
  } else {
    FILE* fp = fopen(outputFileName.Get().c_str(), "w");
    if (!fp) {
      throw FileNotWritable(outputFileName.Get());
    }
    return fp;
  }
}
开发者ID:DavidXZK,项目名称:OpenCC,代码行数:11,代码来源:CommandLine.cpp

示例6: Convert

string Conversion::Convert(const string& phrase) const {
  std::ostringstream buffer;
  for (const char* pstr = phrase.c_str(); *pstr != '\0';) {
    Optional<const DictEntry*> matched = dict->MatchPrefix(pstr);
    size_t matchedLength;
    if (matched.IsNull()) {
      matchedLength = UTF8Util::NextCharLength(pstr);
      buffer << UTF8Util::FromSubstr(pstr, matchedLength);
    } else {
      matchedLength = matched.Get()->KeyLength();
      buffer << matched.Get()->GetDefault();
    }
    pstr += matchedLength;
  }
  return buffer.str();
}
开发者ID:huoxudong125,项目名称:OpenCC,代码行数:16,代码来源:Conversion.cpp

示例7: Segment

DictEntryPtrVectorPtr MaxMatchSegmentation::Segment(const string& text) {
  DictEntryPtrVectorPtr segments(new DictEntryPtrVector);
  const char* pstr = text.c_str();
  while (*pstr != '\0') {
    Optional<DictEntryPtr> matched = dict->MatchPrefix(pstr);
    size_t matchedLength;
    if (matched.IsNull()) {
      matchedLength = UTF8Util::NextCharLength(pstr);
      segments->push_back(DictEntryPtr(new DictEntry(UTF8Util::FromSubstr(pstr, matchedLength))));
    } else {
      matchedLength = matched.Get()->key.length();
      segments->push_back(DictEntryPtr(matched.Get()));
    }
    pstr += matchedLength;
  }
  return segments;
}
开发者ID:BloodySinner,项目名称:OpenCC,代码行数:17,代码来源:MaxMatchSegmentation.cpp


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