Solved

Roguewave's RWCString vs string

Posted on 2000-04-09
7
2,398 Views
Last Modified: 2008-02-01
I'm thinking about using Roguewave's RWCString
class instead of normal strings. Then I though
"Why?" and I started read the documentation,
but I couldn't find any info that would explain
exactly what are the main differences between
it and normal string?

Of course I can't remember every method normal
string class offers and comparing all of them would
to Roguewave's methods would be a little bit
too much work. Has anyone used this class
and what benefits it offers comparing to
normal string class?
0
Comment
Question by:tonitop
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 9

Expert Comment

by:jasonclarke
ID: 2700161
Presumably you are talking about the std::string class.

I would think that one of the main reasons that there is RWCString and not just std::string is that RWCString has been around for most people for a lot longer.  RWCString was available long before std::string was,  I was using it at least 7 years ago.

For 'normal' string uses, I guess RWCString probably is similar.  I use std::strings now and don't find myself wishing for RWCString features.
0
 
LVL 3

Expert Comment

by:TEFKASG
ID: 2702536
Are you using other RW classes?  If not, I would just use the std string and not bother with the rogue wave libraries.
  I haven't used RW strings in a while, but as jasonclarke said, using std::strings I don't miss the RW version.  Just my 2 cents worth.
0
 
LVL 9

Expert Comment

by:Pacman
ID: 2703378
Can't tell you the diffs because I only use RWCString.
But what I hate using RWCString is the following:

There's no type cast operator to (char*), only to (const char*).
So if you have a function which wants char* as a parameter (even if it doesn't write to this pointer) then you have to write such code:

RWCString myString = "hi folks!";

DoSomething( (char*)(const char*)myString );

This is ugly. Don't know if your other string class is better here ...

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:jasonclarke
ID: 2703405
std::string doesn't cast to char * or const char* at all, you have to use the c_str() method, which returns a const char*.  (Can't remeber why now,  but I think, as with almost everything in STL there is a good reason for it).

You shouldn't complain about this behaviour in RW, it is the right thing to do.  Casting to char* is really quite bad because, as you say it would give the user the opportunity to stomp on RWs string buffer.  

Forcing you to do this kind of cast is a safety measure,  it highlights that what you are doing is dodgy and best avoided.



0
 
LVL 9

Expert Comment

by:Pacman
ID: 2703473
I know it's right but I don't like it. I've never tried to write to a const char ... ;) ...
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2703878
A comment on RWCString casting... (Following Pacman's comments)

I prefer to change:
DoSomething( (char*)(const char*)myString );

to:

DoSomething( const_cast<char *>( myString.Data()));

or:

DoSomething( (char *) myString.Data());

Double casting seems a little too obscure.  The const_cast version nicely documents what you are doing, although it is a little wordy.  I usually use the last form.
0
 
LVL 2

Accepted Solution

by:
abesoft earned 100 total points
ID: 2703960
Two differences that I've noticed are substrings and regular expressions.  (I don't use std::string too often, so I'm not sure if somebody has implemented these as extensions to the library - I'm sure that they have....)

In std::string::substr( start, end) merely returns a copy of the string between those two positions.  In RWCSubString, you get a reference to the actual string that the substring is extracted from, so:
  RWCString s("What I tell you is true.");
  // Create a substring and use it as an lvalue:
  s(19, 0) = "three times ";
  cout << s << endl;
Program output:

What I tell you is three times true.

Which is kind of neat when you want to modify a portion of a string.

Also, regular expressions are great tools, although they do tend to be difficult to read and maintain, and most developers who use them quickly become addicted.  RW includes two subtly different regexp classes, but that's not really a concern right now.  As an example:  

  RWCString aString("Hark! Hark! the lark");
  // A regular expression matching any lowercase word or end of a  
  //word starting with "l":     RWCRExpr re("l[a-z]*");
  cout << aString(re) << endl;  // Prints "lark"

Both of these features are not strictly part of RWCString, but they do act on RWCStrings, so I consider the classes related.

Hope this helps.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question