From c648bfb346d301580dd36e601e260f6532d3850c Mon Sep 17 00:00:00 2001 From: Tom Conkling Date: Tue, 1 Jul 2008 23:12:45 +0000 Subject: [PATCH] StringUtil.trimEnd() git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5215 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/util/StringUtil.as | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/as/com/threerings/util/StringUtil.as b/src/as/com/threerings/util/StringUtil.as index 51f6a2562..c98e43fe8 100644 --- a/src/as/com/threerings/util/StringUtil.as +++ b/src/as/com/threerings/util/StringUtil.as @@ -21,11 +21,11 @@ package com.threerings.util { +import com.threerings.util.env.Environment; + import flash.utils.ByteArray; import flash.utils.Dictionary; -import com.threerings.util.env.Environment; - public class StringUtil { /** @@ -237,7 +237,7 @@ public class StringUtil } /** - * Utility function that strips whitespace from the ends of a String. + * Utility function that strips whitespace from the beginning and end of a String. */ public static function trim (str :String) :String { @@ -256,6 +256,19 @@ public class StringUtil } } + /** + * Utility function that strips whitespace from the end of a String. + */ + public static function trimEnd (str :String) :String + { + var endIdx :int = str.length - 1; + while (isWhitespace(str.charAt(endIdx))) { + endIdx--; + } + + return (endIdx >= 0 ? str.slice(0, endIdx + 1) : ""); + } + /** * @return true if the specified String is == to a single whitespace character. */ @@ -493,7 +506,7 @@ public class StringUtil str += "\n"; } return str; - + }