Solved

Roguewave's RWCString vs string

Posted on 2000-04-09
7
2,428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create string splitting user defined function in C++ 23 353
C Language combined operators 28 136
mixing C++ & C# in Vis Studio 2013 7 276
FMX StringGrid1->Canvas->FillRect Problem 3 219
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

739 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