PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/Rusty/Core/String.cs

http://github.com/polyethene/IronAHK
C# | 756 lines | 472 code | 81 blank | 203 comment | 93 complexity | 66e0533179b969341620660566936685 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Globalization;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Windows.Forms;
  10. namespace IronAHK.Rusty
  11. {
  12. partial class Core
  13. {
  14. /// <summary>
  15. /// Returns the Unicode value (an integer between 1 and 65535) for the specified character in a string.
  16. /// </summary>
  17. /// <param name="str">A string.</param>
  18. /// <param name="n">The zero-based character position in the string.
  19. /// If this is blank it is assumed to be <c>0</c>.</param>
  20. /// <returns>The Unicode value.
  21. /// If <paramref name="str"/> is empty or <paramref name="n"/> is specified out of bounds, <c>0</c> is returned.</returns>
  22. public static int Asc(string str, int n = 0)
  23. {
  24. return string.IsNullOrEmpty(str) || n < 0 || n > str.Length ? 0 : (int)str[n];
  25. }
  26. /// <summary>
  27. /// Encodes binary data to a base 64 character string.
  28. /// </summary>
  29. /// <param name="value">The data to encode.</param>
  30. /// <returns>A base 64 string representation of the given binary data.</returns>
  31. public static string Base64Encode(object value)
  32. {
  33. return Convert.ToBase64String(ToByteArray(value));
  34. }
  35. /// <summary>
  36. /// Decodes a base 64 character string to binary data.
  37. /// </summary>
  38. /// <param name="s">The base 64 string to decode.</param>
  39. /// <returns>A binary byte array of the given sequence.</returns>
  40. public static byte[] Base64Decode(string s)
  41. {
  42. return Convert.FromBase64String(s);
  43. }
  44. /// <summary>
  45. /// Returns the single character corresponding to a Unicode value.
  46. /// </summary>
  47. /// <param name="n">A Unicode value.</param>
  48. /// <returns>A Unicode character whose value is <paramref name="n"/>.</returns>
  49. public static string Chr(int n)
  50. {
  51. return ((char)n).ToString();
  52. }
  53. /// <summary>
  54. /// Transforms a YYYYMMDDHH24MISS timestamp into the specified date/time format.
  55. /// </summary>
  56. /// <param name="output">The variable to store the result.</param>
  57. /// <param name="stamp">Leave this parameter blank to use the current local date and time.
  58. /// Otherwise, specify all or the leading part of a timestamp in the YYYYMMDDHH24MISS format.</param>
  59. /// <param name="format">
  60. /// <para>If omitted, it defaults to the time followed by the long date,
  61. /// both of which will be formatted according to the current user's locale.</para>
  62. /// <para>Otherwise, specify one or more of the date-time formats,
  63. /// along with any literal spaces and punctuation in between.</para>
  64. /// </param>
  65. public static void FormatTime(out string output, string stamp, string format)
  66. {
  67. DateTime time;
  68. if (stamp.Length == 0)
  69. time = DateTime.Now;
  70. else
  71. {
  72. try
  73. {
  74. time = ToDateTime(stamp);
  75. }
  76. catch (ArgumentOutOfRangeException)
  77. {
  78. output = null;
  79. return;
  80. }
  81. }
  82. switch (format.ToLowerInvariant())
  83. {
  84. case Keyword_Time:
  85. format = "t";
  86. break;
  87. case Keyword_ShortDate:
  88. format = "d";
  89. break;
  90. case Keyword_LongDate:
  91. format = "D";
  92. break;
  93. case Keyword_YearMonth:
  94. format = "Y";
  95. break;
  96. case Keyword_YDay:
  97. output = time.DayOfYear.ToString();
  98. return;
  99. case Keyword_YDay0:
  100. output = time.DayOfYear.ToString().PadLeft(3, '0');
  101. return;
  102. case Keyword_WDay:
  103. output = time.DayOfWeek.ToString();
  104. return;
  105. case Keyword_YWeek:
  106. {
  107. int week = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  108. output = time.ToString("Y") + week;
  109. return;
  110. }
  111. default:
  112. if (format.Length == 0)
  113. format = "f";
  114. break;
  115. }
  116. try
  117. {
  118. output = time.ToString(format);
  119. }
  120. catch (FormatException)
  121. {
  122. output = null;
  123. }
  124. }
  125. /// <summary>
  126. /// Encodes binary data to a hexadecimal string.
  127. /// </summary>
  128. /// <param name="value">The data to encode.</param>
  129. /// <returns>A hexadecimal string representation of the given binary data.</returns>
  130. public static string HexEncode(object value)
  131. {
  132. return ToString(ToByteArray(value));
  133. }
  134. /// <summary>
  135. /// Decodes a hexadecimal string to binary data.
  136. /// </summary>
  137. /// <param name="hex">The hexadecimal string to decode.</param>
  138. /// <returns>A binary byte array of the given sequence.</returns>
  139. public static byte[] HexDecode(string hex)
  140. {
  141. var binary = new byte[hex.Length / 2];
  142. for (int i = 0; i < hex.Length; i += 2)
  143. {
  144. var n = new string(new[] { hex[i], hex[i + 1] });
  145. binary[i / 2] = byte.Parse(n, NumberStyles.AllowHexSpecifier);
  146. }
  147. return binary;
  148. }
  149. /// <summary>
  150. /// Returns the position of the first or last occurrence of the specified substring within a string.
  151. /// </summary>
  152. /// <param name="input">The string to check.</param>
  153. /// <param name="needle">The substring to search for.</param>
  154. /// <param name="caseSensitive"><c>true</c> to use a case sensitive comparison, <c>false</c> otherwise.</param>
  155. /// <param name="index">The one-based starting character position.
  156. /// Specify zero or leave blank to search in reverse, i.e. right to left.</param>
  157. /// <returns>The one-based index of the position of <paramref name="needle"/> in <paramref name="input"/>.
  158. /// A value of zero indicates no match.</returns>
  159. public static int InStr(string input, string needle, bool caseSensitive = false, int index = 1)
  160. {
  161. var compare = caseSensitive ? StringComparison.Ordinal : A_StringComparison;
  162. const int offset = 1;
  163. if (index == 0)
  164. return offset + input.LastIndexOf(needle, compare);
  165. if (index < 0 || index > input.Length)
  166. return 0;
  167. return offset + input.IndexOf(needle, index - 1, compare);
  168. }
  169. /// <summary>
  170. /// Determines whether a string contains a pattern (regular expression).
  171. /// </summary>
  172. /// <param name="input">The input string.</param>
  173. /// <param name="needle">The pattern to search for, which is a regular expression.</param>
  174. /// <param name="output">The variable to store the result.</param>
  175. /// <param name="index">The one-based starting character position.
  176. /// If this is less than one it is considered an offset from the end of the string.</param>
  177. /// <returns>The one-based index of the position of the first match.
  178. /// A value of zero indicates no match.</returns>
  179. public static int RegExMatch(string input, string needle, out string[] output, int index)
  180. {
  181. Regex exp;
  182. bool reverse = index < 1;
  183. try { exp = ParseRegEx(needle, reverse); }
  184. catch (ArgumentException)
  185. {
  186. output = new string[] { };
  187. ErrorLevel = 2;
  188. return 0;
  189. }
  190. if (index < 0)
  191. {
  192. int l = input.Length - 1;
  193. input = input.Substring(0, Math.Min(l, l + index));
  194. index = 0;
  195. }
  196. index = Math.Max(0, index - 1);
  197. Match res = exp.Match(input, index);
  198. var matches = new string[res.Groups.Count];
  199. for (int i = 0; i < res.Groups.Count; i++)
  200. matches[i] = res.Groups[i].Value;
  201. output = matches;
  202. return matches.Length == 0 ? 0 : res.Groups[0].Index + 1;
  203. }
  204. /// <summary>
  205. /// Replaces occurrences of a pattern (regular expression) inside a string.
  206. /// </summary>
  207. /// <param name="input">The input string.</param>
  208. /// <param name="needle">The pattern to search for, which is a regular expression.</param>
  209. /// <param name="replace">The string to replace <paramref name="needle"/>.</param>
  210. /// <param name="count">The variable to store the number of replacements that occurred.</param>
  211. /// <param name="limit">The maximum number of replacements to perform.
  212. /// If this is below one all matches will be replaced.</param>
  213. /// <param name="index">The one-based starting character position.
  214. /// If this is less than one it is considered an offset from the end of the string.</param>
  215. /// <returns>The new string.</returns>
  216. public static string RegExReplace(string input, string needle, string replace, out int count, int limit = -1, int index = 1)
  217. {
  218. Regex exp;
  219. try
  220. {
  221. exp = ParseRegEx(needle, index < 1);
  222. }
  223. catch (ArgumentException)
  224. {
  225. count = 0;
  226. ErrorLevel = 2;
  227. return null;
  228. }
  229. if (limit < 1)
  230. limit = int.MaxValue;
  231. if (index < 1)
  232. index = input.Length + index - 1;
  233. index = Math.Min(Math.Max(0, index), input.Length);
  234. var n = 0;
  235. MatchEvaluator match = delegate(Match hit)
  236. {
  237. n++;
  238. return replace;
  239. };
  240. count = n;
  241. var result = exp.Replace(input, match, limit, index);
  242. return result;
  243. }
  244. /// <summary>
  245. /// Arranges a variable's contents in alphabetical, numerical, or random order optionally removing duplicates.
  246. /// </summary>
  247. /// <param name="input">The variable whose contents to use as the input.</param>
  248. /// <param name="options">See the remarks.</param>
  249. /// <remarks>
  250. /// <list type="table">
  251. /// <listheader>
  252. /// <term>Name</term>
  253. /// <description>Description</description>
  254. /// </listheader>
  255. /// <item>
  256. /// <term>C</term>
  257. /// <description>Case sensitive.</description>
  258. /// </item>
  259. /// <item>
  260. /// <term>CL</term>
  261. /// <description>Case sensitive based on current user's locale.</description>
  262. /// </item>
  263. /// <item>
  264. /// <term>D<c>x</c></term>
  265. /// <description>Specifies <c>x</c> as the delimiter character which is <c>`n</c> by default.</description>
  266. /// </item>
  267. /// <item>
  268. /// <term>F <c>name</c></term>
  269. /// <description>Use the return value of the specified function for comparing two items.</description>
  270. /// </item>
  271. /// <item>
  272. /// <term>N</term>
  273. /// <description>Numeric sorting.</description>
  274. /// </item>
  275. /// <item>
  276. /// <term>P<c>n</c></term>
  277. /// <description>Sorts items based on character position <c>n</c>.</description>
  278. /// </item>
  279. /// <item>
  280. /// <term>R</term>
  281. /// <description>Sort in reverse order.</description>
  282. /// </item>
  283. /// <item>
  284. /// <term>Random</term>
  285. /// <description>Sort in random order.</description>
  286. /// </item>
  287. /// <item>
  288. /// <term>U</term>
  289. /// <description>Remove any duplicate items.</description>
  290. /// </item>
  291. /// <item>
  292. /// <term>Z</term>
  293. /// <description>Considers a trailing delimiter as a boundary which otherwise would be ignored.</description>
  294. /// </item>
  295. /// <item>
  296. /// <term>\</term>
  297. /// <description>File path sorting.</description>
  298. /// </item>
  299. /// </list>
  300. /// </remarks>
  301. public static void Sort(ref string input, params string[] options)
  302. {
  303. var opts = KeyValues(string.Join(",", options), true, new[] { 'f' });
  304. MethodInfo function = null;
  305. if (opts.ContainsKey('f'))
  306. {
  307. function = FindLocalRoutine(opts['f']);
  308. if (function == null)
  309. return;
  310. }
  311. char split = '\n';
  312. if (opts.ContainsKey('d'))
  313. {
  314. string s = opts['d'];
  315. if (s.Length == 1)
  316. split = s[0];
  317. opts.Remove('d');
  318. }
  319. string[] list = input.Split(new[] { split }, StringSplitOptions.RemoveEmptyEntries);
  320. if (split == '\n')
  321. {
  322. for (int i = 0; i < list.Length; i++)
  323. {
  324. int x = list[i].Length - 1;
  325. if (list[i][x] == '\r')
  326. list[i] = list[i].Substring(0, x);
  327. }
  328. }
  329. if (opts.ContainsKey('z') && input[input.Length - 1] == split)
  330. {
  331. Array.Resize(ref list, list.Length + 1);
  332. list[list.Length - 1] = string.Empty;
  333. opts.Remove('z');
  334. }
  335. bool withcase = false;
  336. if (opts.ContainsKey('c'))
  337. {
  338. string mode = opts['c'];
  339. if (mode == "l" || mode == "L")
  340. withcase = false;
  341. else
  342. withcase = true;
  343. opts.Remove('c');
  344. }
  345. bool numeric = false;
  346. if (opts.ContainsKey('n'))
  347. {
  348. numeric = true;
  349. opts.Remove('n');
  350. }
  351. int sortAt = 1;
  352. if (opts.ContainsKey('p'))
  353. {
  354. if (!int.TryParse(opts['p'], out sortAt))
  355. sortAt = 1;
  356. opts.Remove('p');
  357. }
  358. bool reverse = false, random = false;
  359. if (opts.ContainsKey(Keyword_Random[0]))
  360. {
  361. if (opts[Keyword_Random[0]].Equals(Keyword_Random.Substring(1), StringComparison.OrdinalIgnoreCase)) // Random
  362. random = true;
  363. else
  364. reverse = true;
  365. opts.Remove(Keyword_Random[0]);
  366. }
  367. bool unique = false;
  368. if (opts.ContainsKey('u'))
  369. {
  370. unique = true;
  371. opts.Remove('u');
  372. }
  373. bool slash = false;
  374. if (opts.ContainsKey('\\'))
  375. {
  376. slash = true;
  377. opts.Remove('\\');
  378. }
  379. var comp = new CaseInsensitiveComparer();
  380. var rand = new Random();
  381. Array.Sort(list, delegate(string x, string y)
  382. {
  383. if (function != null)
  384. {
  385. object value = null;
  386. try { value = function.Invoke(null, new object[] { new object[] { x, y } }); }
  387. catch (Exception) { }
  388. int result;
  389. if (value is string && int.TryParse((string)value, out result))
  390. return result;
  391. return 0;
  392. }
  393. else if (x == y)
  394. return 0;
  395. else if (random)
  396. return rand.Next(-1, 2);
  397. else if (numeric)
  398. {
  399. int a, b;
  400. return int.TryParse(x, out a) && int.TryParse(y, out b) ?
  401. a.CompareTo(b) : x.CompareTo(y);
  402. }
  403. else
  404. {
  405. if (slash)
  406. {
  407. int z = x.LastIndexOf('\\');
  408. if (z != -1)
  409. x = x.Substring(z + 1);
  410. z = y.LastIndexOf('\\');
  411. if (z != -1)
  412. y = y.Substring(z + 1);
  413. if (x == y)
  414. return 0;
  415. }
  416. return withcase ? x.CompareTo(y) : comp.Compare(x, y);
  417. }
  418. });
  419. if (unique)
  420. {
  421. int error = 0;
  422. var ulist = new List<string>(list.Length);
  423. foreach (var item in list)
  424. if (!ulist.Contains(item))
  425. ulist.Add(item);
  426. else
  427. error++;
  428. ErrorLevel = error;
  429. list = ulist.ToArray();
  430. }
  431. if (reverse)
  432. Array.Reverse(list);
  433. input = string.Join(split.ToString(), list);
  434. }
  435. /// <summary>
  436. /// Returns the length of a string.
  437. /// </summary>
  438. /// <param name="input">The input string.</param>
  439. /// <returns>The total length of the string, including any invisbile characters such as null.</returns>
  440. public static int StrLen(string input)
  441. {
  442. return input.Length;
  443. }
  444. /// <summary>
  445. /// Converts a string to lowercase.
  446. /// </summary>
  447. /// <param name="output">The variable to store the result.</param>
  448. /// <param name="input">The variable whose contents to use as the input.</param>
  449. /// <param name="title"><c>true</c> to use title casing, <c>false</c> otherwise.</param>
  450. public static void StringLower(out string output, ref string input, bool title)
  451. {
  452. output = title ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input) : input.ToLowerInvariant();
  453. }
  454. /// <summary>
  455. /// Replaces the specified substring with a new string.
  456. /// </summary>
  457. /// <param name="output">The variable to store the result.</param>
  458. /// <param name="input">The variable whose contents to use as the input.</param>
  459. /// <param name="search">The substring to search for.</param>
  460. /// <param name="replace">The string to replace <paramref name="search"/>.</param>
  461. /// <param name="all"><c>true</c> to replace all instances, <c>false</c> otherwise.</param>
  462. /// <remarks>If <paramref name="all"/> is true and <see cref="A_StringCaseSense"/> is on a faster replacement algorithm is used.</remarks>
  463. public static void StringReplace(out string output, ref string input, string search, string replace, bool all)
  464. {
  465. if (IsAnyBlank(input, search, replace))
  466. {
  467. output = string.Empty;
  468. return;
  469. }
  470. var compare = _StringComparison ?? StringComparison.OrdinalIgnoreCase;
  471. if (all && compare == StringComparison.Ordinal)
  472. output = input.Replace(search, replace);
  473. else
  474. {
  475. var buf = new StringBuilder(input.Length);
  476. int z = 0, n = 0, l = search.Length;
  477. while (z < input.Length && (z = input.IndexOf(search, z, compare)) != -1)
  478. {
  479. if (n < z)
  480. buf.Append(input, n, z - n);
  481. buf.Append(replace);
  482. z += l;
  483. n = z;
  484. }
  485. if (n < input.Length)
  486. buf.Append(input, n, input.Length - n);
  487. output = buf.ToString();
  488. }
  489. }
  490. /// <summary>
  491. /// Separates a string into an array of substrings using the specified delimiters.
  492. /// </summary>
  493. /// <param name="output">The variable to store the result.</param>
  494. /// <param name="input">The variable whose contents to use as the input.</param>
  495. /// <param name="delimiters">One or more characters (case sensitive), each of which is used to determine
  496. /// where the boundaries between substrings occur in <paramref name="input"/>.
  497. /// If this is blank each character of <paramref name="input"/> will be treated as a substring.</param>
  498. /// <param name="trim">An optional list of characters (case sensitive) to exclude from the beginning and end of each array element.</param>
  499. public static void StringSplit(out string[] output, ref string input, string delimiters, string trim)
  500. {
  501. if (delimiters.Length == 0)
  502. {
  503. var list = new List<string>(input.Length);
  504. foreach (var letter in input)
  505. if (trim.IndexOf(letter) == -1)
  506. list.Add(letter.ToString());
  507. output = list.ToArray();
  508. return;
  509. }
  510. output = input.Split(delimiters.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  511. if (trim.Length != 0)
  512. {
  513. char[] omit = trim.ToCharArray();
  514. for (int i = 0; i < output.Length; i++)
  515. output[i] = output[i].Trim(omit);
  516. }
  517. }
  518. /// <summary>
  519. /// Converts a string to uppercase.
  520. /// </summary>
  521. /// <param name="output">The variable to store the result.</param>
  522. /// <param name="input">The variable whose contents to use as the input.</param>
  523. /// <param name="title"><c>true</c> to use title casing, <c>false</c> otherwise.</param>
  524. public static void StringUpper(out string output, ref string input, bool title)
  525. {
  526. output = title ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input) : input.ToUpperInvariant();
  527. }
  528. /// <summary>
  529. /// Retrieves one or more characters from the specified position in a string.
  530. /// </summary>
  531. /// <param name="input">The string to use.</param>
  532. /// <param name="index">The one-based starting character position.
  533. /// If this is less than one it is considered an offset from the end of the string.</param>
  534. /// <param name="length">The maximum number of characters to retrieve.
  535. /// Leave this parameter blank to return the entire leading part of the string.
  536. /// Specify a negative value to omit that many characters from the end of the string.</param>
  537. /// <returns>The new substring.</returns>
  538. public static string SubStr(string input, int index, int length = int.MaxValue)
  539. {
  540. if (string.IsNullOrEmpty(input) || length == 0)
  541. return string.Empty;
  542. if (index < 1)
  543. index += input.Length;
  544. index--;
  545. if (index < 0 || index >= input.Length)
  546. return string.Empty;
  547. int d = input.Length - index;
  548. if (length < 0)
  549. length += d;
  550. length = Math.Min(length, d);
  551. return input.Substring(index, length);
  552. }
  553. /// <summary>
  554. /// Performs miscellaneous math functions, bitwise operations, and tasks such as ASCII to Unicode conversion.
  555. /// This function is obsolete, please use the related newer syntax.
  556. /// <seealso cref="Asc"/>
  557. /// <seealso cref="Chr"/>
  558. /// <seealso cref="Mod"/>
  559. /// <seealso cref="Exp"/>
  560. /// <seealso cref="Sqrt"/>
  561. /// <seealso cref="Log"/>
  562. /// <seealso cref="Ln"/>
  563. /// <seealso cref="Round"/>
  564. /// <seealso cref="Ceil"/>
  565. /// <seealso cref="Floor"/>
  566. /// <seealso cref="Abs"/>
  567. /// <seealso cref="Sin"/>
  568. /// <seealso cref="Cos"/>
  569. /// <seealso cref="Tan"/>
  570. /// <seealso cref="ASin"/>
  571. /// <seealso cref="ACos"/>
  572. /// <seealso cref="ATan"/>
  573. /// <seealso cref="Floor"/>
  574. /// <seealso cref="Floor"/>
  575. /// </summary>
  576. [Obsolete]
  577. public static void Transform(ref string OutputVar, string Cmd, string Value1, string Value2)
  578. {
  579. OutputVar = string.Empty;
  580. switch (Cmd.Trim().ToLowerInvariant())
  581. {
  582. case Keyword_Unicode:
  583. if (Value1 == null)
  584. OutputVar = Clipboard.GetText();
  585. else OutputVar = Value1;
  586. break;
  587. case Keyword_Asc:
  588. OutputVar = char.GetNumericValue(Value1, 0).ToString();
  589. break;
  590. case Keyword_Chr:
  591. OutputVar = char.ConvertFromUtf32(int.Parse(Value1));
  592. break;
  593. case Keyword_Deref:
  594. // TODO: dereference transform
  595. break;
  596. case "html":
  597. OutputVar = Value1
  598. .Replace("\"", "&quot;")
  599. .Replace("&", "&amp;")
  600. .Replace("<", "&lt;")
  601. .Replace(">", "&gt;")
  602. .Replace("\n", "<br/>\n");
  603. break;
  604. case Keyword_Mod:
  605. OutputVar = (double.Parse(Value1) % double.Parse(Value2)).ToString();
  606. break;
  607. case Keyword_Pow:
  608. OutputVar = Math.Pow(double.Parse(Value1), double.Parse(Value2)).ToString();
  609. break;
  610. case Keyword_Exp:
  611. OutputVar = Math.Pow(double.Parse(Value1), Math.E).ToString();
  612. break;
  613. case Keyword_Sqrt:
  614. OutputVar = Math.Sqrt(double.Parse(Value1)).ToString();
  615. break;
  616. case Keyword_Log:
  617. OutputVar = Math.Log10(double.Parse(Value1)).ToString();
  618. break;
  619. case Keyword_Ln:
  620. OutputVar = Math.Log(double.Parse(Value1), Math.E).ToString();
  621. break;
  622. case Keyword_Round:
  623. int p = int.Parse(Value2);
  624. OutputVar = Math.Round(double.Parse(Value1), p == 0 ? 1 : p).ToString();
  625. break;
  626. case Keyword_Ceil:
  627. OutputVar = Math.Ceiling(double.Parse(Value1)).ToString();
  628. break;
  629. case Keyword_Floor:
  630. OutputVar = Math.Floor(double.Parse(Value1)).ToString();
  631. break;
  632. case Keyword_Abs:
  633. double d = double.Parse(Value1);
  634. OutputVar = (d < 0 ? d * -1 : d).ToString();
  635. break;
  636. case Keyword_Sin:
  637. OutputVar = Math.Sin(double.Parse(Value1)).ToString();
  638. break;
  639. case Keyword_Cos:
  640. OutputVar = Math.Cos(double.Parse(Value1)).ToString();
  641. break;
  642. case Keyword_Tan:
  643. OutputVar = Math.Tan(double.Parse(Value1)).ToString();
  644. break;
  645. case Keyword_Asin:
  646. OutputVar = Math.Asin(double.Parse(Value1)).ToString();
  647. break;
  648. case Keyword_Acos:
  649. OutputVar = Math.Acos(double.Parse(Value1)).ToString();
  650. break;
  651. case Keyword_Atan:
  652. OutputVar = Math.Atan(double.Parse(Value1)).ToString();
  653. break;
  654. case Keyword_BitNot:
  655. OutputVar = (~int.Parse(Value1)).ToString();
  656. break;
  657. case Keyword_BitAnd:
  658. OutputVar = (int.Parse(Value1) & int.Parse(Value2)).ToString();
  659. break;
  660. case Keyword_BitOr:
  661. OutputVar = (int.Parse(Value1) | int.Parse(Value2)).ToString();
  662. break;
  663. case Keyword_BitXor:
  664. OutputVar = (int.Parse(Value1) ^ int.Parse(Value2)).ToString();
  665. break;
  666. case Keyword_BitShiftLeft:
  667. OutputVar = (int.Parse(Value1) << int.Parse(Value2)).ToString();
  668. break;
  669. case Keyword_BitShiftRight:
  670. OutputVar = (int.Parse(Value1) >> int.Parse(Value2)).ToString();
  671. break;
  672. }
  673. }
  674. }
  675. }