Solved

Roguewave's RWCString vs string

Posted on 2000-04-09
7
2,341 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now