BizHawk/BizHawk.Client.Common/lua/EmuLuaLibrary.String.cs

95 lines
1.9 KiB
C#
Raw Normal View History

2014-01-20 15:26:44 +00:00
using System;
namespace BizHawk.Client.Common
{
public class StringLuaLibrary : LuaLibraryBase
{
public override string Name { get { return "string"; } }
public override string[] Functions
{
get
{
return new[]
{
"binary",
"hex",
"octal",
2014-01-20 17:06:09 +00:00
"trim",
"replace",
"toupper",
"tolower",
"startswith",
"substring",
"contains",
"endswith",
2014-01-20 15:26:44 +00:00
};
}
}
public static string string_hex(object num)
{
string hex = String.Format("{0:X}", LuaLong(num));
if (hex.Length == 1) hex = "0" + hex;
return hex;
}
public static string string_binary(object num)
{
string binary = Convert.ToString( LuaLong(num), 2);
binary = binary.TrimStart('0');
return binary;
}
public static string string_octal(object num)
{
string octal = Convert.ToString(LuaLong(num),8);
if (octal.Length == 1) octal = "0" + octal;
return octal;
}
2014-01-20 15:26:44 +00:00
2014-01-20 17:15:30 +00:00
public static string string_trim(string str)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.Trim();
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static string string_replace(string str, string str2, string replace)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.Replace(str2,replace);
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static string string_toupper(string str)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.ToUpper();
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static string string_tolower(string str)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.ToLower();
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static string string_substring(string str, object position, object length)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.Substring((int) position,(int) length);
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static string string_remove(string str, object position, object count)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.Remove((int) position,(int) (count));
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static bool string_contains(string str, string str2)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.Contains(str2);
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static bool string_startswith(string str, string str2)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.StartsWith(str2);
2014-01-20 17:06:09 +00:00
}
2014-01-20 17:15:30 +00:00
public static bool string_endswith(string str, string str2)
2014-01-20 17:06:09 +00:00
{
2014-01-20 17:15:30 +00:00
return str.EndsWith(str2);
2014-01-20 17:06:09 +00:00
}
2014-01-20 15:26:44 +00:00
}
}