Beispiel #1
0
        static RantFormat()
        {
	        English = new RantFormat();
            English.TitleCaseExclusions.AddRange(
                "a", "an", "the", "that", "where", "when", "for", "any", "or", "and", "of", "in", "at", "as", "into", "if",
                "are", "you", "why", "from");
        }
Beispiel #2
0
 static RantFormat()
 {
     English = new RantFormat();
     English.TitleCaseExclusions.AddRange(
         "a", "an", "the", "that", "where", "when", "for", "any", "or", "and", "of", "in", "at", "as", "into", "if",
         "are", "you", "why", "from");
 }
Beispiel #3
0
 static RantFormat()
 {
     English = new RantSystemFormat
     {
         IndefiniteArticles = IndefiniteArticles.English
     };
     English.InternalAddTitleCaseExclusions(
         "a", "an", "the", "that", "where", "when", "for", "any", "or", "and", "of", "in", "at", "as", "into", "if",
         "are", "you", "why", "from");
 }
Beispiel #4
0
        internal Channel(string name, ChannelVisibility visibility, RantFormat format, Limit limit)
        {
            Name = name;
            Visiblity = visibility;
            _currentBuffer = new StringBuilder(InitialBufferSize);
            _buffers = new List<StringBuilder>{_currentBuffer};
            _format = format;
	        _articles = false;
	        _limit = limit;
        }
Beispiel #5
0
        public ChannelWriter(RantFormat formatStyle, Limit sizeLimit)
        {
            _sizeLimit = sizeLimit;
            _main = new Channel("main", ChannelVisibility.Public, formatStyle, _sizeLimit);

            _stack = new List<Channel> { _main };
            _stackSize = 1;

            _channels = new Dictionary<string, Channel>
            {
                { "main", _main }
            };
        }
Beispiel #6
0
 static RantFormat()
 {
     English = new RantFormat();
     German  = new RantFormat(CultureInfo.GetCultureInfo("de-DE"),
                              new WritingSystem(new[]
     {
         'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
         'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
         'ä', 'ö', 'ü', 'ß'
     }, " ", new QuotationMarks('\u201e', '\u201c', '\u201a', '\u2018')),
                              new string[0],
                              new EnglishPluralizer(),
                              new GermanNumberVerbalizer());
 }
Beispiel #7
0
        public void OpenChannel(string channelName, ChannelVisibility visibility, RantFormat formatStyle)
        {   
            Channel ch;
            if (!_channels.TryGetValue(channelName, out ch))
            {
                ch = new Channel(channelName, visibility, formatStyle, _sizeLimit);
                _channels[channelName] = ch;
            }

            if (channelName == "main") return;

            ch.Visiblity = visibility;

            if (_stack.Contains(ch)) return;
            _stack.Add(ch);
            _stackSize++;
        }
Beispiel #8
0
        public string Format(string input, RantFormat formatStyle, OutputFormatterOptions options = OutputFormatterOptions.None)
        {
            if (String.IsNullOrEmpty(input)) return input;

			// Check for special symbols
			// TODO: Move symbols to a dictionary
			switch (input.ToLowerInvariant())
			{
				case SymbolCodes.EnDash:
					return Symbols.EnDash;
				case SymbolCodes.EmDash:
					return Symbols.EmDash;
				case SymbolCodes.Copyright:
					return Symbols.Copyright;
				case SymbolCodes.RegisteredTM:
					return Symbols.RegisteredTM;
				case SymbolCodes.Trademark:
					return Symbols.Trademark;
				case SymbolCodes.Bullet:
					return Symbols.Bullet;
				case SymbolCodes.Eszett:
					return Symbols.Eszett;
			}

            switch (Case)
            {
                case Case.Lower:
                    input = input.ToLower();
                    break;
                case Case.Upper:
                    input = input.ToUpper();
                    break;
                case Case.First:
                    input = RegCapsFirst.Replace(input, m => m.Value.ToUpper());
                    if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) Case = Case.None;
                    break;
                case Case.Title:
                    if (((options & OutputFormatterOptions.IsArticle) == OutputFormatterOptions.IsArticle || formatStyle.Excludes(input)) && Char.IsWhiteSpace(_lastChar)) break;

                    input = RegCapsTitleWord.Replace(input, m => (
                        _lastChar == '\0'
                        || Char.IsSeparator(_lastChar)
                        || Char.IsWhiteSpace(_lastChar))
                        || Char.IsPunctuation(_lastChar)
                        ? m.Value.ToUpper() : m.Value);
                    break;
                case Case.Sentence:
                    if (_sentence) input = Regex.Replace(input, @"^.*?\w", m => {
                        if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _sentence = false;
                        return m.Value.ToUpper();
                    });
                    input = RegCapsSentenceA.Replace(input, m => m.Value.ToUpper());                    
                    break;
                case Case.Word:
                    input = RegCapsTitleWord.Replace(input, m => m.Value.ToUpper());
                    break;
            }
            if (RegCapsSentenceB.IsMatch(input) && (options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _sentence = true;
            if ((options & OutputFormatterOptions.NoUpdate) != OutputFormatterOptions.NoUpdate) _lastChar = input[input.Length - 1];
            return input;
        }
Beispiel #9
0
		public Sandbox(RantEngine engine, RantPattern pattern, RNG rng, int sizeLimit = 0)
		{
			_engine = engine;
			_format = engine.Format;
			_sizeLimit = new Limit(sizeLimit);
			_mainOutput = new ChannelWriter(_format, _sizeLimit);
			_outputs = new Stack<ChannelWriter>();
			_outputs.Push(_mainOutput);
			_rng = rng;
			_startingGen = rng.Generation;
			_pattern = pattern;
			_objects = new ObjectStack(engine.Objects);
			_blocks = new Stack<BlockState>();
			_matches = new Stack<Match>();
			_queryState = new QueryState();
			_subroutineArgs = new Stack<Dictionary<string, RantAction>>();
			_syncManager = new SyncManager(this);
            _blockManager = new BlockManager();
			_scriptObjectStack = new Stack<object>();
            _stopwatch = new Stopwatch();
		}