1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-18 10:38:31 +02:00
VVVVVV/mobile_version/src/starling/utils/StringUtil.as
Terry Cavanagh 72d018ea04 Update mobile version to mobile v2.2.1
The android version just got a much needed update to fix some resolution issues on devices with cutouts.

It turns out the mobile source was actually pretty out of date, like 3 versions out of date! This commit brings it up to date.

All the changes have just been about keeping the game running on modern devices, though. The biggest change was adding the Starling library to the project, which made the game GPU powered and sped the whole thing up.
2022-12-02 18:19:58 +01:00

96 lines
3.6 KiB
ActionScript

// =================================================================================================
//
// Starling Framework
// Copyright Gamua GmbH. All Rights Reserved.
//
// This program is free software. You can redistribute and/or modify it
// in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================
package starling.utils
{
import starling.errors.AbstractClassError;
/** A utility class with methods related to the String class. */
public class StringUtil
{
/** @private */
public function StringUtil() { throw new AbstractClassError(); }
/** Formats a String in .Net-style, with curly braces ("{0}"). Does not support any
* number formatting options yet. */
public static function format(format:String, ...args):String
{
// TODO: add number formatting options
for (var i:int=0; i<args.length; ++i)
format = format.replace(new RegExp("\\{"+i+"\\}", "g"), args[i]);
return format;
}
/** Replaces a string's "master string" — the string it was built from —
* with a single character to save memory. Find more information about this AS3 oddity
* <a href="http://jacksondunstan.com/articles/2260">here</a>.
*
* @param string The String to clean
* @return The input string, but with a master string only one character larger than it.
* @author Jackson Dunstan, JacksonDunstan.com
*/
public static function clean(string:String):String
{
return ("_" + string).substr(1);
}
/** Removes all leading white-space and control characters from the given String.
*
* <p>Beware: this method does not make a proper Unicode white-space check,
* but simply trims all character codes of '0x20' or below.</p>
*/
public static function trimStart(string:String):String
{
var pos:int;
var length:int = string.length;
for (pos = 0; pos < length; ++pos)
if (string.charCodeAt(pos) > 0x20) break;
return string.substring(pos, length);
}
/** Removes all trailing white-space and control characters from the given String.
*
* <p>Beware: this method does not make a proper Unicode white-space check,
* but simply trims all character codes of '0x20' or below.</p>
*/
public static function trimEnd(string:String):String
{
for (var pos:int = string.length - 1; pos >= 0; --pos)
if (string.charCodeAt(pos) > 0x20) break;
return string.substring(0, pos + 1);
}
/** Removes all leading and trailing white-space and control characters from the given
* String.
*
* <p>Beware: this method does not make a proper Unicode white-space check,
* but simply trims all character codes of '0x20' or below.</p>
*/
public static function trim(string:String):String
{
var startPos:int, endPos:int;
var length:int = string.length;
for (startPos = 0; startPos < length; ++startPos)
if (string.charCodeAt(startPos) > 0x20) break;
for (endPos = string.length - 1; endPos >= startPos; --endPos)
if (string.charCodeAt(endPos) > 0x20) break;
return string.substring(startPos, endPos + 1);
}
}
}