C++中国語記号の処理例の詳細

1323 ワード

C++は中国語の記号を処理します
英文記号を英文カンマに置換

processPunctuation(string& tag)
{
  std::set punctuation_set;
  punctuation_set.insert(' ');
  punctuation_set.insert('\t');
  punctuation_set.insert(';');

  for (int i=0; i< tag.size(); i++) {
    if (punctuation_set.find(tag[i]) != punctuation_set.end()) 
    {
      tag[i] = ',';
    }
  }
  return;
}


中国語のカンマを英語のカンマに置き換える

processChinesePunctuation(string& tag)
{
  string u8comma = u8",";
  for (int i = 0; i < tag.size() - u8comma.size() + 1; i++)
  {
    bool find = true;
    //         UTF-8    
    for (int j = 0; j < u8comma.size(); j++)
    {
      if (tag[i + j] != u8comma[j])
      {
        find = false;
        break;
      }
    }  

    if (find)
    {
      //     ,
      tag[i] = ',';
      auto it = tag.begin();
      it += i + 1;
      for (int j = 1; j < u8comma.size(); j++)
        it = tag.erase(it);
    }
  }
  return;
}



読書に感謝して、みんなを助けることができることを望んで、みんなの当駅に対する支持に感謝します!