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);
}
}