stringparser.cs

来自「CSharpDevelop:这是一个包含源代码的C#、VB.NET的编辑器。」· CS 代码 · 共 83 行

CS
83
字号
// StringParser.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using SharpDevelop.Tool.Data;

namespace SharpDevelop.Tool.Text {
	
	/// <summary>
	/// this class parses internal @ tags of sd.
	/// </summary>
	
	public class StringParser {
		public static string Parse(string str)
		{
			return Parse(str, new string[,] {});
		}
		public static string Parse(string str, string[,] custom_tags)
		{
			string back = "";
			for (int i = 0; i < str.Length; ++i) {
				if (str[i] != '@')
					back+= str[i];
				else {
					++i;
					string token = "";
					while (str[i] != '@')
						token += str[i++];
					
					switch (token.ToUpper()) {
						case "":
							back += "@";
						break;
						case "DATE": // current date
							back += DateTime.Today.ToShortDateString();
						break;
						case "TIME": // current time
							back += DateTime.Now.ToShortTimeString();
						break;
						default:
							int k = token.IndexOf(':');
							bool processcustom = true;
							if (k > 0) {
								processcustom = false;
								switch (token.Substring(0, k).ToUpper()) {
									case "RES":
										back += Resource.GetString(token.Substring(k + 1));
										break;
									default:
										processcustom = true;
										break;
								}
							}
							if (processcustom)
							for (int j = 0; j < custom_tags.GetLength(0); ++j) {
								if (token == custom_tags[j, 0].ToUpper()) {
									back += custom_tags[j, 1].Replace(' ', '_').Replace('\t', '_');
									break;
								}
							}
						break;
					}
				}
			}
			return back;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?