c++ - Selective iterator -


FYI: no boost, yes it is, I want to change the wheel again ;)

Is there a form of selective iterator (possible) in C ++? What do I want to do to isolate the strings like this:

  something: word {or other  

in a form like this:

  something: word {or other  

I can do this with two ends and find_first_of (":") and ("{") Disabled I feel that I might have thought that there would be a way to create / define / write which would be repeated with all the values ​​for_each, I am afraid that I have a fulfillment The custom method must be typed - std :: string is a very complex iterator class.

So I thought maybe it would be:

  std :: vector & lt; Size_t> List; Size_t index = mystring.find (":"); While (index! = Std :: string :: npos) {list.push_back (index); Index = mystring.find (":", list.back ()); } Std :: for_each (list.begin (), list.end (), adspace (mestring));  

This seems to be messing up for me, and I'm pretty sure there is a more wonderful way to do this. But I can not think about it. Anyone have a bright idea? Thank you

PS: I did not post the code, I'll try it as soon as I try it

UPDATE: After taking into consideration all your answers, I have this, and this is my Works for likes :). It considers the last four as a new line or something else, otherwise a <<> code <{/ code>, } , or : will not be processed.

Cancellation (string and line) {char oneBack = ''; Char two backs = ''; Four current = ''; Size_t length = line.image (); (Size_t index = 0; index; lt; length; ++ index) {two backs = one back; Oneback = current; Current = line (Index); If (special (one back)) {if (! (!)) (Insert before the line) / insert {line.inert (index-1, ""); ++ index; ++ Length; } If ((release (current)) // insert {line.insert (index, ""); ++ index; ++ Length; Comments are welcome as usual :)

  std :: string const str = "Something: Word {or other} "; Std :: string result; Result.reserve (str.size ()); (Std :: string :: const_iterator it = str.begin (), end = str.end (); it! = End; ++ it) {if (isalnum (* this)) {result.push_back (* this) ; } And {results push_back (''); Result.push_back (this *); Results. Push_back (''); }}  

Enter the version for speed up

  std :: string str = "something: word {or other"]; (For std :: string :: iterator = str.begin (), end = str.end (); it! = End; ++ it) {if (! Isalnum (* it)) {it = str.insert (This, '') + 2; This = str.insert (this, ''); End = str.end (); }}  

Note that std :: string :: insert inserts before inserting the itater and returns an inserted character to the newly inserted character. Assign is important because buffer can be reallocated to any other memory location (iterators have been canceled by entry). Also keep in mind that you can not keep end for the whole loop, whenever you insert, you want to compress it again.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -