]> granicus.if.org Git - icinga2/commitdiff
Implement String#trim
authorMichael Friedrich <michael.friedrich@netways.de>
Tue, 26 Jan 2016 14:59:29 +0000 (15:59 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 23 Feb 2016 08:35:05 +0000 (09:35 +0100)
fixes #11037

doc/18-language-reference.md
doc/19-library-reference.md
lib/base/string-script.cpp

index 7a2f2cde6e011702e9a5a6d3a85a9d857f5860d1..4d2b88d06f2aa014339e18ffca723041a2619d11 100644 (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
index 176af163a66c1afdcb12486c77a18eb4ba9c23c8..503de7b98fa925a5cc8d5987acab45b47d44b7e2 100644 (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.
index d1d3e03926dfecd272698142b59daf23eb6a0b33..83aef1b19bb108423c68f69d0205d3dd86fa19ee 100644 (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;