It has become an accepted convention to put implementation details in a sub-namespace called detail. Users know to stay away from those.Replace is the public interface of the free function that you should call to do the work.
Then they will wrap ReplaceInternal that will do the actual replacing.
But ReplaceInternal shouldn't be called directly because 1) it takes a bool that should not be passed directly and 2) it has only one version - the one that takes a range. Therefore ReplaceInternal should be hidden away from prying eyes, but since it's free it cannot.
True, the compiler doesn't actually enforce this, but accidentally typing 'detail::' does not sound plausible to me.Code:namespace mystuff { namespace detail { // Implementation details here. } // Interface stuff here. }
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
If I understand you right, then you probably want to replace "This" with "That" in following sentence:
"This is a tree."
Right?
So if in your example Replace(what, with, start, end):
what - "This"
with - "That"
Then how will your generic solution compare if the sequence to be replaced is actually equal to "This", which is not a single word, but, generically speaking, a sequence of elements.
How will you compare such sequence within the destination sequence, which needs the replacement!?!
I am speaking generically! Reusable ofcourse!!
Other wise forget the bling-bling-blah!
And, just think, how to replace words within a string, in simple yet efficient manner!
Extra features never hurt! Make them some default arguments! So I need not concern myself with them!If you only want to perform and search and replace within a specific region.However, there will also be overloads that doesn't take start or begin (will perform search & replace on whole string).
Err hello? How it a problem to replace a string? We've done that a hundred times and that implementation is already done. A long time ago.
Yes, also unfortunately, the C++ standard forbids initializing default arguments with a non-static value (I think I'm getting this right), and also references must be initialized with a const value.Extra features never hurt! Make them some default arguments! So I need not concern myself with them!
So,
Therefore, I overloaded the function:Code:void foo(int i = 0); // OK, constant class cfoo { int some_member; void foo(int i = some_member); // Illegal, not static };
You can choose whichever version suits you best.Code:void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith); void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith, const const_iterator& vStart); void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith, const const_iterator& vStart, const const_iterator& vEnd);
So you are not writing a single generic function that could replace any sequence with another sequence? Ok never mind.
Thanks for you efforts. I just want to do this:Yes, also unfortunately, the C++ standard forbids initializing default arguments with a non-static value (I think I'm getting this right), and also references must be initialized with a const value.
You can choose whichever version suits you best.Code:void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith); void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith, const const_iterator& vStart); void Replace(const CTmplStringBase& strReplaceWhat, const CTmplStringBase& strReplaceWith, const const_iterator& vStart, const const_iterator& vEnd);
Code:CStringEx("This is ${NAME}!").Replace("${NAME}", getName());
I don't know what you're on about.
Code:Strings::CStringEx str = "This is a tree"; cout << str << endl; // This is a tree str.Replace("This", "That"); cout << str << endl; // That is a treeDon't worry - you have it!Thanks for you efforts. I just want to do this:
Code:CStringEx("This is ${NAME}!").Replace("${NAME}", getName());
Well replacing (as in the real meaning), is easy, but only if the "with" is equal in length to "what".
Otherwise see this string:
CStringEx str("Name: {1}\nOver draft {2}\nInterest {3}\n");
and this Replace usage:
Do you see, that, every replacement is increasing the string size?Code:str.Replace("{1}", "Elysia Petralovech"); str.Replace("{2}", "7500.50"); str.Replace("{3}", "250.50");
And do you also see that this is basically a sub-sequence insertion over the deletion?
Does that sound a generic solution bell?
May be a generic == operator also, which can compare sub-sequences and return start/end iterator pair?
// I think they have brain washed me more than enough, boy, I am also thinking generically now!!!
It would work with any given type, but it only works on a element basis.
You can't expect a sequence of values to be treated as one value or element.
Boost isn't letting me define a proper return type for my operators -/+...
After that... well... Well, after that's over and done with, I guess major testing is due.
Then I could release an alpha.
I got it (I was thinking something similar).
I understand the '+', but what is '-' for?Boost isn't letting me define a proper return type for my operators -/+...
After that... well... Well, after that's over and done with, I guess major testing is due.
Would you enable this in your string class?
Code:CStringEx str; int age = 23; float cm = 167.1f; str << "She is " << age << " years old, " << cm << " centimeter high!" << endl;
[Iterators.
Iter1 + Iter2
OR
Iter1 - Iter2
I really need to implement a range iterator here or some such. A lot of thinking left there.
No, but this would work:
Or rather, float and doubles don't work. At least not yet, but maybe in the future. But integers works.Code:CStringEx str; int age = 23; float cm = 167.1f; str = "She is "+ age + " years old, " + cm + " centimeter high!"; cout << str << endl;
Ok got it
That's even better! I already feel like being in heaven!No, but this would work:
Or rather, float and doubles don't work. At least not yet, but maybe in the future. But integers works.Code:CStringEx str; int age = 23; float cm = 167.1f; str = "She is "+ age + " years old, " + cm + " centimeter high!"; cout << str << endl;
Release your implementation pretty soon!!