June 2003
- Damage and Stuff (Math and Code) Ben Chambers
- MMO Launch issues ruining potential segments of the market. Derek Licciardi
- MMO Launch issues ruining potential segments of the market. Mike Shaver
- MMO Launch issues ruining potential segments of the market. Daniel Anderson
- MMO Launch issues ruining potential segments of the market. Chris Holko
- MMO Launch issues ruining potential segments of the market. Matt Mihaly
- MMO Launch issues ruining potential segments of the market. Daniel.Harman@barclayscapital.com
- MMO Launch issues ruining potential segments of the market. Justin Coleman
- MMO Launch issues ruining potential segments of th e market. Daniel.Harman@barclayscapital.com
- MMO Launch issues ruining potential segments of th e market. Jeff Fuller
- MMO Launch issues ruining potential segments of the market. Matt Mihaly
- MMO Launch issues ruining potential segments of the market. Luca Girardo
- New Column by Dave Rickey "Engines of Creation" Now at Skotos Christopher Allen
- Announcing Shadow Door: an NPC Control Interface for Neverwinter Nights Robert Zubek
- ADMIN: So, what has been happening? J C Lawrence
- [Meta] Forward of moderated message J C Lawrence
- New Here MIKE MacMartin
- New Here Mike
On Thu, 2003-06-19 at 21:16, MIKE MacMartin wrote:
> The prompt I'm looking for is /C$N/r>/x ... which, before the
> colour substitution (/ is the colour escape, $ is the string
> escape), flips the order of the > and the name ($N is the acting
> character's name).
> Here is the code I've got written (using C++ and std::string):
> string CCharacter::expand(string fmt, bool victim) {
> string::size_type pos = 0;
> while ((pos = fmt.find('$', pos + 1)), pos != string::npos) {
> fmt.insert(pos + 2, text(fmt[pos+1], victim));
> fmt.erase(pos, 2);
> }
> return fmt;
> }
Welcome to the list. =)
Now on to your question...
This may be a style thing, but...
Do this. Change your while from
while ((pos = fmt.find('$', pos + 1)), pos != string::npos) {
to
while (pos != string::npos) { // string::npos is -1
pos = fmt.find('$',pos + 1);
if (pos != string:: npos) {
// work the string in here
}
}
You may (possibly) be running into a compiler optimisation thing
where it's doing the npos check prior to the = in the while loop.
Either reformatting the code (int equality checks are minimal CPU
usage, esp in the context of your string interations) or turning off
optimisations will expose that.
You could also try compiling without optimisations.
Perhaps adding the "pos" as a character to your
My gut reaction is that you're looping too many times (either by
embedded $ chars in the std::map lookup or because of the while()
condition not correctly triggering.
There's virtually no way you're going to do a string::insert call
that far off unless 1) your 'pos' var is way off or 2) the string is
munged and the pos is correct...giving you the corrupted output.
Unless you invalidate an iterator (which you're not using anyways)
there shouldn't be any issues with a string::find() after a
string::insert(). Of course, that assumes a non-buggy STL
implementation. (ie, some MS)
www.dinkumware.com or similiar recommended.
-Mike
- New Here Mike
- Looking for a GUI Mud Development program Snicker Furfoot
- Looking for a GUI Mud Development program Ben Greear
- ADMIN: List archives are now restored. J C Lawrence
- The Price of Being Male Rayzam
- The Price of Being Male Sasha Hart
- The Price of Being Male Daniel.Harman@barclayscapital.com
- The Price of Being Male Rayzam
- The Price of Being Male Byron Ellacott
- The Price of Being Male Dr. Cat
- The Price of Being Male Castronova, Edward
- The Price of Being Male Boyle, Paul
- The Price of Being Male Mark 'Kamikaze' Hughes
- The Price of Being Male Rayzam
- The Price of Being Male Mark 'Kamikaze' Hughes
- The Price of Being Male Rayzam
- The Price of Being Male Mark 'Kamikaze' Hughes
- The Price of Being Male Marian Griffith
- The Price of Being Male Paul Schwanz
- The Price of Being Male Rayzam
- The Price of Being Male Paul Schwanz
- The Price of Being Male Vincent Archer
- The Price of Being Male Rayzam
- The Price of Being Male Castronova, Edward
- The Price of Being Male Sasha Hart
- The Price of Being Male Mark 'Kamikaze' Hughes
- The Price of Being Male Amanda Walker
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Castronova, Edward
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Tazzik
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Tazzik
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Marian Griffith
- The Price of Being Male Sasha Hart
- The Price of Being Male Tom
- The Price of Being Male Marian Griffith
- The Price of Being Male Sasha Hart
- The Price of Being Male Marian Griffith
- The Price of Being Male Sasha Hart
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Castronova, Edward
- The Price of Being Male Richard A. Bartle
- The Price of Being Male Daniel.Harman@barclayscapital.com
- The Price of Being Male Paul Schwanz
- The Price of Being Male Daniel Anderson
- The Price of Being Male Travis Casey
- The Price of Being Male Paul Schwanz
- The Price of Being Male Travis Casey
- The Price of Being Male Chris Holko
- The Price of Being Male Travis Casey
- The Price of Being Male Sanvean
- The Price of Being Male Sasha Hart
- The Price of Being Male Tom
- The Price of Being Male Sanvean
- The Price of Being Male Paul Schwanz
- The Price of Being Male Amanda Walker
- The Price of Being Male shop@isparkinson.co.uk
- The Price of Being Male Boyle, Paul
- The Price of Being Male Ola Fosheim Grøstad
- The Price of Being Male Sheela Caur'Lir
- The Price of Being Male Jeff Crane
- Are gold pieces taxable? Koster, Raph
- Are gold pieces taxable? Boyle, Paul
- Are gold pieces taxable? Amanda Walker
- Are gold pieces taxable? Thomas Leavitt
- Are gold pieces taxable? Daniel.Harman@barclayscapital.com
- Functors / Loki (was: New Here) Eli Stevens
- Architecture Peter "Pietro" Rossmann
- Architecture Peter "Pietro" Rossmann
- Architecture ceo
- Architecture Peter "Pietro" Rossmann
- SW:G this is so unfair Marian Griffith
- SW:G this is so unfair Marc Bowden
- SW:G this is so unfair Martin Bassie
- Players policing themselves (was: MMO Launch issues ruining potential segments of themarket.) Derek Licciardi
- Q&A with Ken Troop, Lead Designer at Turbine Michael Tresca
- Q&A with Ken Troop, Lead Designer at Turbine Threshold RPG
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) Zach Collins {Siege}
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) Daniel.Harman@barclayscapital.com
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) Rossmann Peter
- Architecture (Cell Rebalancing) ceo
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) J C Lawrence
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) J C Lawrence
- Architecture (Cell Rebalancing) Rossmann Peter
- Architecture (Cell Rebalancing) Rossmann Peter
- Architecture (Cell Rebalancing) J C Lawrence
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann
- Architecture (Cell Rebalancing) Daniel.Harman@barclayscapital.com
- Architecture (Cell Rebalancing) Peter "Pietro" Rossmann