Implement String#trim

fixes #11037
This commit is contained in:
Michael Friedrich 2016-01-26 15:59:29 +01:00
parent 4185c75d8a
commit 22c21ebd61
3 changed files with 17 additions and 1 deletions

View File

@ -879,7 +879,7 @@ type objects are made available using global variables which match the type's na
The type object's `prototype` property can be used to find out which methods a certain type
supports:
/* This returns: ["contains","find","len","lower","replace","reverse","split","substr","to_string","upper"] */
/* This returns: ["contains","find","len","lower","replace","reverse","split","substr","to_string","trim","upper"] */
keys(String.prototype)
Additional documentation on type methods is available in the

View File

@ -508,6 +508,14 @@ Signature:
Returns a copy of the string in reverse order.
### <a id="string-trim"></a> String#trim
Signature:
function trim();
Removes trailing whitespaces and returns the string.
## <a id="object-type"></a> Object type
This is the base type for all types in the Icinga application.

View File

@ -133,6 +133,13 @@ static String StringReverse(void)
return self.Reverse();
}
static String StringTrim(void)
{
ScriptFrame *vframe = ScriptFrame::GetCurrentFrame();
String self = vframe->Self;
return self.Trim();
}
Object::Ptr String::GetPrototype(void)
{
static Dictionary::Ptr prototype;
@ -149,6 +156,7 @@ Object::Ptr String::GetPrototype(void)
prototype->Set("contains", new Function(WrapFunction(StringContains), true));
prototype->Set("replace", new Function(WrapFunction(StringReplace), true));
prototype->Set("reverse", new Function(WrapFunction(StringReverse), true));
prototype->Set("trim", new Function(WrapFunction(StringTrim), true));
}
return prototype;