Exemplo n.º 1
0
        public static string UnionStringEnumPropertyTypeFormatter(Type enumType, QuoteStyle quoteStyle)
        {
            var quote = quoteStyle == QuoteStyle.Double ? "\"" : "'";
            var names = enumType.GetEnumNames();

            return(string.Join(" | ", names.Select(n => $"{quote}{n}{quote}")));
        }
Exemplo n.º 2
0
        public Dialect(bool doubleQuote, char delimiter, char quote, char escape,
			bool skipInitialSpace, string lineTerminator, QuoteStyle quoting,
			bool strict, bool hasHeader)
        {
            _doubleQuote = doubleQuote;
            _delimiter = delimiter;
            _quote = quote;
            _escape = escape;
            _skipInitialSpace = skipInitialSpace;
            _lineTerminator = lineTerminator;
            _quoting = quoting;
            _strict = strict;
            _hasHeader = hasHeader;

            if (_delimiter == '\0')
                _error = "Delimiter must be set";

            if (CheckQuoting() == false)
                _error = "Bad \"quoting\" value";

            if (_quoting != QuoteStyle.QUOTE_NONE && _quote == '\0')
                _error = "Quotechar must be set if quoting enabled";

            if (_lineTerminator == null)
                _error = "Line terminator must be set";
        }
Exemplo n.º 3
0
        public static string Quote(this string text, QuoteStyle style)
        {
            // Use whichever quote character is less frequent
            if (style == QuoteStyle.SingleOrDouble) {
                var singleQuotes = 0;
                var doubleQuotes = 0;
                foreach (var c in text) {
                    if (c == '"') doubleQuotes++;
                    else if (c == '\'') singleQuotes++;
                }
                style = singleQuotes <= doubleQuotes ? QuoteStyle.Single : QuoteStyle.Double;
            }

            // Generate the string using substrings of unquoted stuff for speed
            var quote = style == QuoteStyle.Single ? "'" : "\"";
            var builder = new StringBuilder();
            var start = 0;
            builder.Append(quote);
            for (var i = 0; i < text.Length; i++) {
                var c = text[i];
                string escape;
                if (c == quote[0]) escape = "\\" + quote;
                else if (c == '\\') escape = "\\\\";
                else if (c == '\t') escape = "\\t";
                else if (c == '\n') escape = "\\n";
                else continue;
                builder.Append(text.Substring(start, i - start));
                builder.Append(escape);
                start = i + 1;
            }
            builder.Append(text.Substring(start));
            builder.Append(quote);
            return builder.ToString();
        }
Exemplo n.º 4
0
 public static Quote CreateInstance(string text, QuoteStyle style, SuperHero superHero)
 {
     return(new Quote()
     {
         Text = text,
         QuoteStyle = style,
         SuperHero = superHero
     });
 }
Exemplo n.º 5
0
 public static ICollection <string> ListAllQuotesOfType(QuoteStyle quoteStyle)
 {
     using (var context = new SamuraiContext())
     {
         return(context.Quotes
                .Where(q => q.QuoteStyle == quoteStyle)
                .Select(q => q.Text).ToList());
     }
 }
Exemplo n.º 6
0
 public static List <Quote> ReadAllQuotesWithSpecificQuoteStyle(QuoteStyle quoteStyle)
 {
     using (var context = new SamuraiContext())
     {
         return(context.Quotes
                .Where(q => q.QuoteStyle == quoteStyle)
                .Include(q => q.Samurai)
                .ToList());;
     }
 }
Exemplo n.º 7
0
    public void MakeQuote(Animator animator, string QuoteString, Color PanelColor, Color TextColor,
                          HumanBodyBones PlaceBone, Vector2 PlaceOffset, Vector2 PanelCollar, AnchorPresets anchor,
                          PivotPresets pivot, QuoteStyle quoteStyle, int ListMax, AlphaStyle alphaStyle, BackImage backImage, float alphaTime,
                          Vector3 moveDirection, float movingTime, int fontSize, Font font)
    {
        GameObject    imObj  = new GameObject();
        RectTransform imRect = imObj.AddComponent <RectTransform>();

        imRect.SetPivot(pivot);
        imRect.SetAnchor(anchor);
        imObj.transform.SetParent(GameObject.Find("Canvas").GetComponent <RectTransform>());
        Image image = imObj.AddComponent <Image>();

        image.color = PanelColor;
        if (backImage == BackImage.None)
        {
            image.color = new Color(0, 0, 0, 0);
        }
        else
        {
            image.type   = Image.Type.Sliced;
            image.sprite = Resources.Load <Sprite>("_Sprites/" + backImage.ToString());
        }

        GameObject    texObj = new GameObject();
        RectTransform tra    = texObj.AddComponent <RectTransform>();

        texObj.transform.SetParent(imObj.GetComponent <RectTransform>());
        Text text = texObj.AddComponent <Text>();

        text.supportRichText = true;
        text.font            = font;
        text.fontSize        = fontSize;
        text.text            = QuoteString;
        text.color           = TextColor;

        text.rectTransform.sizeDelta  = new Vector2(text.preferredWidth, text.preferredHeight);
        text.rectTransform.sizeDelta  = new Vector2(text.preferredWidth, text.preferredHeight);
        image.rectTransform.sizeDelta = text.rectTransform.sizeDelta + PanelCollar;
        tra.anchoredPosition          = Vector2.zero;

        if (!quoteCtrl.Select(q => q.anim).Any(a => a == animator) || quoteCtrl.Count == 0)
        {
            QuoteController c = gameObject.AddComponent <QuoteController>();
            c.anim = animator;
            quoteCtrl.Add(c);
        }
        int CtrlIndex = quoteCtrl.Select(q => q.anim).ToList().IndexOf(animator);

        QuoteEnter(new QuoteStyles(imRect, PlaceBone, PlaceOffset, quoteStyle, alphaStyle, ListMax, alphaTime, movingTime, moveDirection), CtrlIndex);
        imObj.transform.localScale = Vector3.one;
        //imObj.SetActive(false);
        //imObj.SetActive(true);
    }
Exemplo n.º 8
0
 private static void ListAllQuotesOfType(QuoteStyle quoteStyle)
 {
     ch.Line("ListAllQuotesOfType");
     using (var context = new SamuraiContext())
     {
         foreach (var quote in context.Quotes.Where(q => q.Style == quoteStyle))
         {
             ch.Green(quote.Text);
         }
     }
 }
Exemplo n.º 9
0
 private static void ListAllQuotesOfType_WithSamurai(QuoteStyle quoteStyle)
 {
     ch.Line("ListAllQuotesOfType_WithSamurai");
     using (var context = new SamuraiContext())
     {
         foreach (var quote in context.Quotes.Where(q => q.Style == quoteStyle).Include(q => q.Samurai))
         {
             ch.Green($"'{quote.Text}' is a {quoteStyle.ToString().ToLower()} quote by {quote.Samurai.Name}");
         }
     }
 }
Exemplo n.º 10
0
 private static void ListAllQuotesOfType_WithSamurai_Fail(QuoteStyle quoteStyle)
 {
     ch.Line("ListAllQuotesOfType_WithSamurai");
     using (var context = new SamuraiContext())
     {
         foreach (var quote in context.Quotes.Where(q => q.Style == quoteStyle))
         {
             // quote.Samurai will be null
             ch.Green($"'{quote.Text}' is a {quoteStyle} quote by {quote.Samurai.Name}");
         }
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CsvFormat"/> class.
        /// </summary>
        /// <param name="delimiter">The delimiter.</param>
        /// <param name="quote">The quote.</param>
        /// <param name="style">The style.</param>
        /// <param name="ignoreWhitespaces">if set to <c>true</c> leading and trailing whitespaces will be ignored.</param>
        /// <exception cref="ArgumentException">If the delimiter is equals to the quote</exception>
        public CsvFormat(char delimiter = ',', char quote = '"', QuoteStyle style = QuoteStyle.WhenNeeded, bool ignoreWhitespaces = true)
        {
            if (delimiter == quote)
            {
                throw new ArgumentException("delimiter cannot be equals to the quote");
            }

            Delimiter        = delimiter;
            Quote            = quote;
            Style            = style;
            IgnoreWhitespace = ignoreWhitespaces;
        }
Exemplo n.º 12
0
        public static void ListAllQuotesOfType(QuoteStyle quoteStyle)
        {
            using (var context = new SamuraiContext())
            {
                var quotes = context.Quotes.Where(s => s.QuoteStyle == quoteStyle);

                foreach (var quote in quotes)
                {
                    Console.WriteLine(quote.Text);
                }
            }
        }
Exemplo n.º 13
0
 private static void ListAllQuotesOfType(QuoteStyle quoteStyle)
 {
     using (var context = new SamuraiContext())
     {
         var quotes = from s in context.Quotes
                      where s.Quality == quoteStyle
                      select s;
         foreach (var quote in quotes)
         {
             Console.WriteLine(quote.Text);
         }
     }
 }
Exemplo n.º 14
0
 public QuoteStyles(RectTransform _panel, HumanBodyBones _bone, Vector3 _PosOffset, QuoteStyle _quoteStyle, AlphaStyle _alphaStyle,
                    float _listMax, float _alphaTime, float _moveTime, Vector3 _moveDirection)
 {
     panel         = _panel;
     bone          = _bone;
     PosOffset     = _PosOffset;
     quoteStyle    = _quoteStyle;
     alphaStyle    = _alphaStyle;
     ListMax       = _listMax;
     alphaTime     = _alphaTime;
     moveTime      = _moveTime;
     moveDirection = _moveDirection;
 }
Exemplo n.º 15
0
        public static char ToChar(this QuoteStyle quoteStyle)
        {
            switch (quoteStyle)
            {
            case QuoteStyle.SingleQuote: return('\'');

            case QuoteStyle.DoubleQuote: return('"');

            case QuoteStyle.Backtick: return('`');

            default: throw new NotSupportedException();
            }
        }
Exemplo n.º 16
0
        private static void ListQuoteAndSamurai(QuoteStyle quoteStyle)
        {
            using (var context = new SamuraiContext())
            {
                var quotes = from s in context.Quotes
                             join Samurai in context.Samurais on s.SamuraiId equals Samurai.Id
                             where s.Quality.Equals(quoteStyle)
                             select new { s.Text, Samurai.Name };

                foreach (var quote in quotes)
                {
                    Console.WriteLine($"\"{quote.Text}\" is a {quoteStyle} quote by {quote.Name}");
                }
            }
        }
Exemplo n.º 17
0
        public static void ListAllQuotesOfType_WithSamurai(QuoteStyle quoteStyle)
        {
            using (var context = new SamuraiContext())
            {
                var samurai = context.Samurais.Include(s => s.Quotes.Where(q => q.QuoteStyle == quoteStyle));

                foreach (var s in samurai)
                {
                    foreach (var q in s.Quotes)
                    {
                        Console.WriteLine($"{q.Text} is a quote by {s.Name}");
                    }
                }
            }
        }
Exemplo n.º 18
0
        public static string ValueNumberEnumFormatter(Type enumType, QuoteStyle quoteStyle)
        {
            var builder = new StringBuilder();

            builder.AppendLine($"enum {enumType.Name} {{");

            foreach (var enumName in enumType.GetEnumNames())
            {
                var value = (int)Enum.Parse(enumType, enumName);
                builder.AppendLine($"{TypeScriptGenerator.TabString}{enumName} = {value},");
            }

            builder.AppendLine("}");

            return(builder.ToString());
        }
Exemplo n.º 19
0
        public Dialect(bool doubleQuote, char delimiter, char quote, char escape,
                       bool skipInitialSpace, string lineTerminator, QuoteStyle quoting,
                       bool strict, bool hasHeader)
        {
            _doubleQuote      = doubleQuote;
            _delimiter        = delimiter;
            _quote            = quote;
            _escape           = escape;
            _skipInitialSpace = skipInitialSpace;
            _lineTerminator   = lineTerminator;
            _quoting          = quoting;
            _strict           = strict;
            _hasHeader        = hasHeader;

            Check();
        }
Exemplo n.º 20
0
        public Dialect(bool doubleQuote, char delimiter, char quote, char escape,
			bool skipInitialSpace, string lineTerminator, QuoteStyle quoting,
			bool strict, bool hasHeader)
        {
            _doubleQuote = doubleQuote;
            _delimiter = delimiter;
            _quote = quote;
            _escape = escape;
            _skipInitialSpace = skipInitialSpace;
            _lineTerminator = lineTerminator;
            _quoting = quoting;
            _strict = strict;
            _hasHeader = hasHeader;

            Check();
        }
Exemplo n.º 21
0
        public static string ValueNamedEnumFormatter(Type enumType, QuoteStyle quoteStyle)
        {
            var builder = new StringBuilder();

            builder.AppendLine($"enum {enumType.Name} {{");

            foreach (var enumName in enumType.GetEnumNames())
            {
                var value = quoteStyle == QuoteStyle.Single ? $"'{enumName}'" : $"\"{enumName}\"";
                builder.AppendLine($"{TypeScriptGenerator.TabString}{enumName} = {value},");
            }

            builder.AppendLine("}");

            return(builder.ToString());
        }
Exemplo n.º 22
0
        public static ICollection <string> ListAllQuotesOfType_WithSamurai(QuoteStyle quoteStyle)
        {
            ICollection <string> output = new List <string>();

            using (var context = new SamuraiContext())
            {
                var relevantQuotes = context.Quotes
                                     .Where(q => q.QuoteStyle == quoteStyle)
                                     .Include(q => q.Samurai);
                foreach (var quote in relevantQuotes)
                {
                    output.Add($"\"{quote.Text}\" is a {quote.QuoteStyle} quote by {quote.Samurai.Name}");
                }
            }

            return(output);
        }
Exemplo n.º 23
0
        public static Quote CreateRandom(Random rng, SuperHero hero)
        {
            var length = rng.Next(1, 10);

            var words = new List <string>()
            {
                "do", "since", "the", "man", "work", "money", "love", "self-importance", "smash", "important", "life", "lives", "hero"
            };

            string text = "";

            for (int i = 0; i < length; i++)
            {
                var currRngIndex = rng.Next(0, words.Count);
                text += words[currRngIndex];
                words.RemoveAt(currRngIndex);
            }

            var quoteStyleRng = rng.Next(0, 4);

            // if RNG lands on either 2 or 3, then it'll be 'Awesome'
            QuoteStyle quoteStyle = Enums.QuoteStyle.Awesome;


            switch (quoteStyleRng)
            {
            case 0:

                quoteStyle = Enums.QuoteStyle.Cheesy;
                break;

            case 1:

                quoteStyle = Enums.QuoteStyle.Lame;
                break;
            }

            return(Quote.CreateInstance(text, quoteStyle, hero));
        }
Exemplo n.º 24
0
 public void Settings(out Color panelColor, out Color textColor,
                      out HumanBodyBones placeBone, out Vector2 placeOffset, out Vector2 panelCollar,
                      out AnchorPresets anchor, out PivotPresets pivot, out QuoteStyle quoteStyle, out int listMax, out AlphaStyle _alphaStyle,
                      out float alphaChangingTime, out Vector3 moveDirection, out float movingTime,
                      out BackImage backImage, out int fontSize, out Font fonts)
 {
     panelColor        = PanelColor;
     textColor         = TextColor;
     placeBone         = PlaceBone;
     placeOffset       = PlaceOffset;
     panelCollar       = PanelCollar;
     anchor            = Anchor;
     pivot             = Pivot;
     quoteStyle        = QuoteStyle;
     listMax           = ListMax;
     _alphaStyle       = alphaStyle;
     alphaChangingTime = AlphaChangingTime;
     moveDirection     = MoveDirection;
     movingTime        = MovingTime;
     backImage         = BackImg;
     fontSize          = FontSize;
     fonts             = font;
 }
Exemplo n.º 25
0
        public string[] ReportQuotesOfType(QuoteStyle style)
        {
            var    result      = new List <string>();
            string stylestring = style.ToString().ToLower();

            foreach (var sam in _context.Samurais)
            {
                string name      = sam.Name;
                int    numQuotes = sam.Quotes.Count(x => x.Style == style);
                if (numQuotes == 0)
                {
                    result.Add($"{name} has no {stylestring} quotes");
                }
                else if (numQuotes == 1)
                {
                    result.Add($"{name} has 1 {stylestring} quote");
                }
                else
                {
                    result.Add($"{name} has {numQuotes} {stylestring} quotes");
                }
            }
            return(result.ToArray());
        }
Exemplo n.º 26
0
 public static InjectionOptions IntoForm(this InjectionOptions injector, string fieldName, string initialValue, Func <IEnumerable <KeyValuePair <string, string> > > formFields = null, QuoteStyle quoteStyle = QuoteStyle.SingleQuote)
 {
     injector.ParameterName = fieldName;
     injector.Location      = InjectionLocation.Form;
     injector.FormFields    = formFields;
     injector.InitialValue  = initialValue;
     injector.ParameterType = typeof(string);
     injector.QuoteStyle    = quoteStyle;
     return(injector);
 }
Exemplo n.º 27
0
 public string[] ReportQuotesOfType(QuoteStyle style)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 28
0
 public CsvRecord WithStyle(QuoteStyle style)
 {
     return(WithFormat(Format.WithStyle(style)));
 }
Exemplo n.º 29
0
 public StyleDesc(QuoteStyle style, string name)
 {
     this.style = style;
     this.name = name;
 }
Exemplo n.º 30
0
 public static void ListAllQuotesOfType_WithSamurai(QuoteStyle quoteStyle)
 {
 }
Exemplo n.º 31
0
 public CsvHeader WithStyle(QuoteStyle style)
 {
     return(WithFormat(Format.WithStyle(style)));
 }
Exemplo n.º 32
0
 public static InjectionOptions AsString(this InjectionOptions injector, string initialValue = null, QuoteStyle quoteStyle = QuoteStyle.SingleQuote)
 {
     injector.InitialValue = initialValue;
     injector.QuoteStyle   = quoteStyle;
     return(injector);
 }
Exemplo n.º 33
0
 public static InjectionOptions IntoQueryStringParameter(this InjectionOptions injector, string parameterName, string initialValue, QuoteStyle quoteStyle = QuoteStyle.SingleQuote)
 {
     injector.ParameterName = parameterName;
     injector.Location      = InjectionLocation.QueryString;
     injector.InitialValue  = initialValue;
     injector.ParameterType = typeof(string);
     injector.QuoteStyle    = quoteStyle;
     return(injector);
 }
Exemplo n.º 34
0
 public TypeScriptGenerator WithQuoteStyle(QuoteStyle style)
 {
     _quoteStyle = style;
     return(this);
 }