Home » U++ Library support » LineEdit, EditFields, DocEdit » How to trim leading and trailing spaces in EditString?
How to trim leading and trailing spaces in EditString? [message #23765] |
Fri, 20 November 2009 10:10  |
Zbych
Messages: 327 Registered: July 2009
|
Senior Member |
|
|
Hi,
What is the simplest way to add a trimming of spaces to EditString?
I tried to add a conversion. It works fine, but EditString stopped reacting to NotNull flag.
Here is the code of my converter:
struct TrimConvert : public Convert {
virtual Value Scan(const Value& text) const {
return TrimBoth(text.ToString());
}
};
Question is what I am doing wrong?
|
|
|
|
Re: How to trim leading and trailing spaces in EditString? [message #23848 is a reply to message #23797] |
Thu, 26 November 2009 10:55   |
Zbych
Messages: 327 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 .
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
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Apr 30 11:45:57 CEST 2025
Total time taken to generate the page: 0.01021 seconds
|