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 » LineEdit, EditFields, DocEdit » How to trim leading and trailing spaces in EditString?
Re: How to trim leading and trailing spaces in EditString? [message #23848 is a reply to message #23797] Thu, 26 November 2009 10:55 Go to previous messageGo to previous message
Zbych is currently offline  Zbych
Messages: 325
Registered: July 2009
Senior Member
luzr wrote on Sun, 22 November 2009 23:28

It is because NotNull is method of StringConvert, so if you replace the Convert, it is your responsibility to test for Null.


Ok, I see Smile.

Maybe you could add trimming to EditString and ConvertString?
file EditCtrl.h:

class EditString : public EditValue<WString, ConvertString> {
[...]
	EditString& TrimSpaces(bool ts = true)           { ConvertString::TrimSpaces(ts); return *this; }
};



file Convert.h:

class ConvertString : public Convert {
[...]
	ConvertString& TrimSpaces(bool b = true)       { trim_spaces = b;  return *this; }
[...]
#ifdef flagSO
	ConvertString(int maxlen = INT_MAX, bool notnull = false, bool trim_spaces = false);
	virtual ~ConvertString();
#else
	ConvertString(int maxlen = INT_MAX, bool notnull = false, bool trim_spaces = false)
		: maxlen(maxlen), notnull(notnull), trim_spaces(trim_spaces) {}
#endif
[...]



file Convert.cpp:

Value ConvertString::Scan(const Value& text) const {
	if(IsError(text)) return text;
	if(IsNull(text)) return notnull ? NotNullError() : Value(text);
	if(text.GetType() == STRING_V && String(text).GetLength() <= maxlen ||
	   text.GetType() == WSTRING_V && WString(text).GetLength() <= maxlen) return trim_spaces ? Value(TrimBoth(text)) : text;
	return ErrorValue(UPP::Format(t_("Please enter no more than %d characters."), maxlen));
}



CtrlLib.usc:

ctrl EditString {
	>EditNotNull;
	bool TrimSpaces;
	raw MaxLen;

	PaintData(w) {
		text = (.NotNull ? "!" : "") + "Str";
		if(.MaxLen != "")
			text << " < " << .MaxLen;
		PaintText(w, text);
	}
}


[Updated on: Thu, 26 November 2009 11:11]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: What is the best way to create a mask in a editfield.
Next Topic: Incorrect position of chars in DocEdit ctrl.
Goto Forum:
  


Current Time: Fri Apr 26 18:38:08 CEST 2024

Total time taken to generate the page: 0.03228 seconds