From: Michael Friedrich Date: Tue, 26 Jan 2016 14:59:29 +0000 (+0100) Subject: Implement String#trim X-Git-Tag: v2.4.2~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b58ddfb158f2b3a4cf5a0dd179d48142a2deca36;p=icinga2 Implement String#trim fixes #11037 --- diff --git a/doc/18-language-reference.md b/doc/18-language-reference.md index 7a2f2cde6..4d2b88d06 100644 --- a/doc/18-language-reference.md +++ b/doc/18-language-reference.md @@ -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 diff --git a/doc/19-library-reference.md b/doc/19-library-reference.md index 176af163a..503de7b98 100644 --- a/doc/19-library-reference.md +++ b/doc/19-library-reference.md @@ -508,6 +508,14 @@ Signature: Returns a copy of the string in reverse order. +### String#trim + +Signature: + + function trim(); + +Removes trailing whitespaces and returns the string. + ## Object type This is the base type for all types in the Icinga application. diff --git a/lib/base/string-script.cpp b/lib/base/string-script.cpp index d1d3e0392..83aef1b19 100644 --- a/lib/base/string-script.cpp +++ b/lib/base/string-script.cpp @@ -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;