続・C++でStringTokenizerっぽいことをやってみる

| | TrackBacks (0)

 前回の記事haveの指摘に従い、参照渡しをやめてヴェクタを返す関数にしてみた。

std::vector<string> 
slice(const std::string source, const std::string dem)
{
  std::string::size_type i1 = 0;
  std::string::size_type i2 = source.find(dem);
  std::vector<string> retval;

  if(std::string::npos == i2)
    return retval;

  std::string s = source + dem;

  do{
    retval.push_back(s.substr(i1, i2-i1));
    i1 = i2+1;
  }while(std::string::npos != (i2 = s.find(dem, i1)));

  return retval;
}

 ちょっと効率は落ちたが、Atomicになったので前回のコードにくらべ、マルチスレッドプログラミングで安全に使えるようになった。

Thanks! nice comment > Have

Categories

0 TrackBacks

Listed below are links to blogs that reference this entry: 続・C++でStringTokenizerっぽいことをやってみる.

TrackBack URL for this entry: http://www.argv.org/~chome/blog/mt-tb.cgi/77

About Me

中尾 圭佐(chomy)
千葉県船橋市在住のモノクロ写真に目覚めた研究者。
Twitter ID: jm6xxu
Skype: chomy

My Tweets

jm6xxu: Yesterday, I joined the summer school at Tsukuba. I could join only one day but i feel it is wonderful to know not knowing.

jm6xxu: VHDLは院生の時に書いたなぁ。簡単なロジックだったけど。最近は、Cからも論理合成できるらしい。RT @habutarou: HDLも大きく2種類あったな。おいらはVHDLを習った。なつかしい… RT @jm6xxu ま、その前にVHDLを思い出さなきゃいけないがな。

jm6xxu: ま、その前にVHDLを思い出さなきゃいけないがな。と思ったら、emacsにverilogモードなんてものがある。debパッケージにもなってるし、Verilogにするか。

jm6xxu: 9月なので本気出す。本格的にFPGAでデバイスを作ることにする。純正ダウンロードケーブルもSuzakuも注文したし、WebPack ISEもダウンロード中。再来週には無料セミナーにも行く。

jm6xxu: 四次元空間はドラえもんのらポケットの中の世界だって? 30点。パイロットは6次元で航空機を制御してる。所詮地ベタて満足してるヤツは自由度がもう一つあるコトを死ぬまで気づかないものさ

About this Entry

This page contains a single entry by chomy published on June 14, 2009 3:16 AM.

C++でStringTokenizerっぽいことをやってみる was the previous entry in this blog.

MacBookPro 購入 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.261