fCraft.ChatColor.StripColors C# (CSharp) Method

StripColors() private method

private StripColors ( [ message ) : string
message [
return string
        public static string StripColors([NotNull] string message) {
            if (message == null) throw new ArgumentNullException("message");
            int start = message.IndexOf('&');
            if (start == -1) {
                return message;
            }
            int lastInsert = 0;
            StringBuilder output = new StringBuilder(message.Length);
            while (start != -1) {
                output.Append(message, lastInsert, start - lastInsert);
                lastInsert = Math.Min(start + 2, message.Length);
                start = message.IndexOf('&', lastInsert);
            }
            output.Append(message, lastInsert, message.Length - lastInsert);
            return output.ToString();
        }

Usage Example

Example #1
0
        public static void Log(LogType type, [NotNull] string message, [NotNull] params object[] args)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (!Enabled)
            {
                return;
            }

            if (args.Length > 0)
            {
                message = String.Format(message, args);
            }

            // occasionally \r\n newlines slip into the system, e.g. in stack traces
            message = message.Replace("\r\n", "\n");
            message = Chat.ReplaceNewlines(message);
            message = Chat.ReplaceEmotesWithUnicode(message);
            message = ChatColor.StripColors(message);

            string line = DecorateLogMessage(type, message);

            lock (LogLock) {
                RaiseLoggedEvent(message, line, type);

                RecentMessages.Enqueue(line);
                while (RecentMessages.Count > MaxRecentMessages)
                {
                    RecentMessages.Dequeue();
                }

                if (LogFileOptions[(int)type])
                {
                    try {
                        File.AppendAllText(Path.Combine(Paths.LogPath, CurrentLogFileName),
                                           line + Environment.NewLine);
                    } catch (Exception ex) {
                        string errorMessage = "Logger.Log: " + ex;
                        RaiseLoggedEvent(errorMessage,
                                         DecorateLogMessage(LogType.Error, errorMessage),
                                         LogType.Error);
                    }
                }
            }
        }