Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Suggestion for StringBuffer
Suggestion for StringBuffer [message #44904] Mon, 20 July 2015 00:50 Go to next message
rxantos is currently offline  rxantos
Messages: 72
Registered: October 2011
Member
Could it be possible to Add

void  Set(const String& s);
StringBuffer(const String& s){ Zero(); Set(s);}

to StringBuffer in uppsrc/Core/String.h
and

void StringBuffer::Set(const String& s)
{
	int len = s.GetLength();
	if(0 < len) {
		SetLength(len);
		memcpy(begin, s.Begin(), len);
	} else {
		Zero();
	}
}

in uppsrc/Core/String.cpp

Sometimes I need top create a string buffer from a constant string to edit in a copy without affecting the original.

[Updated on: Mon, 20 July 2015 00:52]

Report message to a moderator

Re: Suggestion for StringBuffer [message #45084 is a reply to message #44904] Sat, 29 August 2015 07:36 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hi,

after carefully considering this, I tentatively decided it is not a good idea:

a) by adding StringBuffer(const String& s) the action that is going to happen would be quite strangely defined. Consider

void Fn(const String& p) { StringBuffer b(p); }


vs

void Fn(String p) { StringBuffer b(p); }


I would say this would be a great source of accidental errors...

b) Set is in function almost identical to Cat

So, if you need to assign data now, you can use

String s;
StringBuffer b;
b.Cat(s);


I think this is sufficient.

Anyway, all of this is not final. But if I could be convinced we need anything new here, I would rather use

StringBuffer(const String& s, int); // standard way of saying 'deep copy'
void Set(const String& s) { Clear(); Cat(s); } // simpler implementation


Mirek
Previous Topic: Dehaviour of DirectoryExists
Next Topic: VectorMap.Get
Goto Forum:
  


Current Time: Fri Mar 29 13:33:24 CET 2024

Total time taken to generate the page: 0.01515 seconds