示例#1
0
        //------------------------------------------------------------
        // ???
        //public static int Balance(this StringView str, int indexOfOpeningBracketOrQuote) {
        //  var literalStatus = new LiteralStatus();
        //  for (int i = indexOfOpeningBracketOrQuote; i != str.Length; ++i) {
        //    if (str[i].IsBracket()) {
        //      literalStatus.PushBracket(str[i].GetBracketType());
        //      if (literalStatus.Effective) {
        //        return i + 1;
        //      }
        //    }
        //    else if (str[i].IsQuote()) {
        //      literalStatus.PushQuote(str[i].GetQuoteType());
        //      if (literalStatus.Effective) {
        //        return i + 1;
        //      }
        //    }
        //  }
        //  return str.Length;
        //}
        //============================================================

        public static StringView StripBoundaryWhitespaces(this StringView str)
        {
            int p = str.GetFirstSpaceBoundary();
            int n = str.GetLastSpaceBoundary();

            return(str.GetSubView(p, n));
        }
示例#2
0
        //============================================================

        private static int SeekWithoutClamping(this StringView str, int start, SeekMode mode, Ward1D ward)
        {
            if (mode == SeekMode.MoveOneChar)
            {
                return(start + ward.GetOffset());
            }
            else if (mode == SeekMode.UntilNewline)
            {
                if (ward == Ward1D.Backward)
                {
                    return(str.FindLast('\n', start + 1));
                }
                else if (ward == Ward1D.Forward)
                {
                    return(str.FindFirst('\n', start));
                }
            }
            else
            {
                Debug.Assert((mode
                              & (SeekMode.LiterallySpaced | SeekMode.PassingQuotation | SeekMode.BracketBalanced)) != 0);
                if (ward == Ward1D.Backward)
                {
                    return(str.SeekToSpaceBalanced(start, mode, -1, -1) - 1);
                }
                else if (ward == Ward1D.Forward)
                {
                    return(str.SeekToSpaceBalanced(start + 1, mode, 1, 0));
                }
            }
            throw new Exception();
        }
示例#3
0
        //============================================================
        // todo: improve implementation

        // failed
        public static (int lower, int upper) LongestGap(this StringView str, char needle)
        {
            int p         = 0;
            int maxLength = 0;

            (int lower, int upper) = (0, 0);
            for (int i = 0; i != str.Length; ++i)
            {
                if (str[i] == needle)
                {
                    if (i - p > maxLength)
                    {
                        lower = p;
                        upper = i;
                    }
                    p = i;
                }
            }
            if (str.Length - p > maxLength)
            {
                lower = p;
                upper = str.Length;
            }
            return(lower, upper);
        }
示例#4
0
        public static void Append(this StringBuffer stringBuffer, ref byte *dataPointer, StringView format, string[] strings, IntPtr[] argPointers, int argCount)
        {
            var argument = *dataPointer;

            dataPointer += sizeof(ArgumentType);

            var argumentType = (ArgumentType)(argument & ArgumentTypeMask.ArgumentType);

            var hasFormatSpecifier = (argument & ArgumentTypeMask.FormatSpecifier) != 0;

            if (hasFormatSpecifier)
            {
                var formatSpecifier = strings[*dataPointer];
                dataPointer += sizeof(byte);

                fixed(char *p = formatSpecifier)
                {
                    var formatSpecifierView = new StringView(p, formatSpecifier.Length);

                    AppendArg(stringBuffer, ref dataPointer, argumentType, formatSpecifierView, strings, argPointers, argCount);
                }
            }
            else
            {
                AppendArg(stringBuffer, ref dataPointer, argumentType, format, strings, argPointers, argCount);
            }
        }
示例#5
0
 /// <summary>
 /// Creates a token from a string, a position and a length.
 /// </summary>
 /// <param name="text">The value of the token.</param>
 /// <param name="position">The position of the token in the entire query string.</param>
 /// <param name="length">The length of the token.</param>
 public QueryToken(string text, int position, int length)
 {
     this.position   = position;
     this.length     = length;
     this.stringView = new StringView(text);
     this.text       = text;
 }
示例#6
0
        public static string[] LostChallengeChapterRole_ParseGuide(int id, string str)
        {
            //EB.Debug.Log("LostChallengeChapterRole_ParseGuide: id -> {0}, str -> {1}", id, str);
            string[] ret;
            if (!string.IsNullOrEmpty(str))
            {
                List <StringView> views;
                using (ZString.Block())
                {
                    ZString    strID   = ZString.Format("ID_scenes_lost_challenge_chapter_role_{0}_guide", id);
                    string     tmp     = EB.Localizer.GetTableString(strID, str);
                    StringView @string = new StringView(tmp);
                    views = @string.Split2List('|');
                }
                ret = new string[views.Count];
                for (int i = 0; i < views.Count; i++)
                {
                    ret[i] = views[i].ToString();
                }

                if (ret.Length < 2)
                {
                    EB.Debug.LogError("Error Role Config Guide need two string, role id = {0}", id);
                }
                else
                {
                    return(ret);
                }
            }

            return(new string[2]);
        }
示例#7
0
        /// <summary>
        /// Defines a named section for the binary output.
        /// </summary>
        /// <param name="name">The section name.</param>
        /// <param name="starts">The section start address.</param>
        /// <param name="ends">The section end address..</param>
        /// <exception cref="SectionException"/>
        public void DefineSection(StringView name, int starts, int ends)
        {
            if (_started || _sectionCollection.SectionSelected)
            {
                throw new SectionException(1,
                                           "Cannot define a section after assembly has started.");
            }
            if (starts < 0)
            {
                throw new SectionException(1,
                                           $"Section {name} start address {starts} is not valid.");
            }
            if (starts >= ends)
            {
                throw new SectionException(1,
                                           $"Section {name} start address cannot be equal or greater than end address.");
            }
            if (ends > MaxAddress + 1)
            {
                throw new SectionException(1,
                                           $"Section {name} end address {ends} is not valid.");
            }
            switch (_sectionCollection.Add(name, starts, ends))
            {
            case CollectionResult.Duplicate:
                throw new SectionException(1, $"Section {name} already defined.");

            case CollectionResult.RangeOverlap:
                throw new SectionException(1,
                                           $"Section {name} start and end address intersect existing section's.");

            default:
                break;
            }
        }
示例#8
0
        //============================================================
        public static int BalanceBracket(this StringView str, int openingIndex)
        {
            char openingBracket = str[openingIndex];

            Debug.Assert(openingBracket.IsOpeningBracket());
            char closingBracket = openingBracket.CoBracket();
            int  count          = 0;

            for (int i = openingIndex; i != str.Length; ++i)
            {
                if (str[i] == openingBracket)
                {
                    ++count;
                }
                else if (str[i] == closingBracket)
                {
                    --count;
                    if (count == 0)
                    {
                        return(i);
                    }
                }
            }
            return(str.Length);
        }
示例#9
0
        public static unsafe void Format(StringBuffer formatter, DateTime dateTime, StringView format)
        {
            var   tempCharsLength = 4;
            char *tempChars       = stackalloc char[tempCharsLength];

            if (IsStandardShortFormat(format))
            {
                var(year, month, day) = dateTime;
                AppendNumber(formatter, year, 4, tempChars, tempCharsLength);
                formatter.Append('-');
                AppendNumber(formatter, month, 2, tempChars, tempCharsLength);
                formatter.Append('-');
                AppendNumber(formatter, day, 2, tempChars, tempCharsLength);
            }
            else
            {
                var(year, month, day, hour, minute, second, millisecond) = dateTime;
                AppendNumber(formatter, year, 4, tempChars, tempCharsLength);
                formatter.Append('-');
                AppendNumber(formatter, month, 2, tempChars, tempCharsLength);
                formatter.Append('-');
                AppendNumber(formatter, day, 2, tempChars, tempCharsLength);
                formatter.Append(' ');
                AppendNumber(formatter, hour, 2, tempChars, tempCharsLength);
                formatter.Append(':');
                AppendNumber(formatter, minute, 2, tempChars, tempCharsLength);
                formatter.Append(':');
                AppendNumber(formatter, second, 2, tempChars, tempCharsLength);
                formatter.Append('.');
                AppendNumber(formatter, millisecond, 3, tempChars, tempCharsLength);
            }
        }
示例#10
0
 public void Format(StringBuffer buffer, StringView format)
 {
     buffer.Append(A, StringView.Empty);
     buffer.Append("-");
     buffer.Append(B, StringView.Empty);
     buffer.Append("-");
     buffer.Append(C, StringView.Empty);
 }
示例#11
0
 public void Format(StringBuffer buffer, StringView format)
 {
     buffer.Append(this.D, StringView.Empty);
     buffer.Append("-");
     buffer.Append(this.E, StringView.Empty);
     buffer.Append("-");
     buffer.Append(this.F, StringView.Empty);
 }
示例#12
0
        private static ulong DecompMark(StringView str, ref int i)
        {
            int  endMark = str.IndexOf(')', i);
            Vec2 marker  = ParseMarker(str.Substring(i + 1, endMark - i - 1).GetString());

            i = endMark + marker.X;
            return(Decomp2(str.Substring(endMark + 1, marker.X)) * (ulong)marker.Y);
        }
示例#13
0
        public IActionResult Comment(string comment)
        {
            StringView sv = new StringView()
            {
                comment = comment.Split("\r\n").ToList()
            };

            return(View(sv));
        }
示例#14
0
 public static View StringToVoidView(StringView view)
 {
     return (Context context) =>
     {
         var response = view(context);
         if (response != null)
             context.WriteResponse(response);
     };
 }
示例#15
0
 public AddPersonView()
 {
     firstNameView         = new StringView("First Name:");
     lastNameView          = new StringView("Last Name:");
     birthdayView          = new ValueView <DateTime>("Birthday:");
     phoneNumberView       = new StringView("Phone Number:");
     heightView            = new FloatView("Height (in meters)");
     preferedBeveragesRead = new StringListView("Prefered Beverages:");
 }
示例#16
0
 void Awake()
 {
     if (instance != null)
     {
         Destroy(gameObject);
         return;
     }
     instance = this;
 }
示例#17
0
        /// <summary>
        /// Get the start address of a defined section.
        /// </summary>
        /// <param name="name">The section name.</param>
        /// <returns>The section start address, if it is defined.</returns>
        /// <exception cref="Exception"></exception>
        public int GetSectionStart(StringView name)
        {
            var start = _sectionCollection.GetSectionStart(name);

            if (start > int.MinValue)
            {
                return(start);
            }
            throw new Exception($"Section {name} is not defined.");
        }
示例#18
0
        internal static SearchExpression BooleanParser(StringView text)
        {
            var trimmedText = ParserUtils.SimplifyExpression(text);

            if (!bool.TryParse(trimmedText.ToString(), out _))
            {
                return(null);
            }
            return(new SearchExpression(SearchExpressionType.Boolean, text, trimmedText, ConstantEvaluator));
        }
示例#19
0
文件: ArgSet.cs 项目: oktal/ZeroLog
        public void Format(StringBuffer stringBuffer, int index, StringView format)
        {
            var argPointer = (byte *)_argPointers[index + 1].ToPointer();

            var dataPointer = argPointer;

            stringBuffer.Append(ref dataPointer, format, _strings, _argPointers);

            BytesRead += (int)(dataPointer - argPointer);
        }
示例#20
0
        public void AppendTo(StringBuffer stringBuffer, byte *valuePtr, StringView format)
        {
            if (!UnmanagedCache.TryGetFormatter(_typeHandle, out var formatter))
            {
                AppendUnformattedTo(stringBuffer, valuePtr);
                return;
            }

            formatter(stringBuffer, valuePtr, format);
        }
示例#21
0
            public void Format(StringBuffer buffer, StringView format)
            {
                buffer.Append(A, StringView.Empty);

                if (!format.IsEmpty)
                {
                    buffer.Append("[");
                    buffer.Append(format.ToString());
                    buffer.Append("]");
                }
            }
示例#22
0
 public static int NextNonSpace(this StringView str, int start)
 {
     for (int i = start; i != str.Length; ++i)
     {
         if (str[i] != ' ')
         {
             return(i);
         }
     }
     return(str.Length);
 }
示例#23
0
 static void CustomFormat(StringBuffer buffer, Blah blah, StringView format)
 {
     if (format == "yes")
     {
         buffer.Append("World!");
     }
     else
     {
         buffer.Append("(Goodbye)");
     }
 }
示例#24
0
        public IActionResult Comment(string comment)
        {
            StringView sv = new StringView()
            {
                comment = comment.Split("\r\n").ToList()
            };
            string user = HttpContext.Session.GetString("Login");

            user = user != null ? user : "";
            SendStatistic("Default", DateTime.Now, "Info", Request.HttpContext.Connection.RemoteIpAddress.ToString(), true, user);
            return(View(sv));
        }
示例#25
0
 // finding is start from item at index of start
 // return the index of the found item
 // if not found => str.Length
 public static int FindFirst(this StringView str, System.Predicate <char> pred, int start = 0)
 {
     Debug.Assert(start.IsWithinRange(0, str.Length + 1));
     for (int i = start; i != str.Length; ++i)
     {
         if (pred(str[i]))
         {
             return(i);
         }
     }
     return(str.Length);
 }
示例#26
0
        /// <summary>
        /// Sets the current defined section.
        /// </summary>
        /// <param name="section">The section name.</param>
        /// <returns><c>true</c> if the section was able to be selected, otherwise <c>false</c>.</returns>
        /// <exception cref="SectionException"></exception>
        public bool SetSection(StringView section)
        {
            var result = _sectionCollection.SetCurrentSection(section);

            if (result == CollectionResult.NotFound)
            {
                return(false);
            }
            _pc            =
                _logicalPc = _sectionCollection.SelectedStartAddress + _sectionCollection.GetSectionOutputCount();
            return(true);
        }
示例#27
0
 // finding is start from item at index of (start - 1), reversely
 // return the index of the found item plus 1
 // if not found => 0
 public static int FindLast(this StringView str, System.Predicate <char> pred, int start)
 {
     Debug.Assert(start.IsWithinRange(0, str.Length + 1));
     for (int i = start; i != 0; --i)
     {
         if (pred(str[i - 1]))
         {
             return(i);
         }
     }
     return(0);
 }
示例#28
0
        public void CreateInstance_ViewTypeHasDefaultConstructor_ReturnView()
        {
            // Setup
            var viewInfo = new ViewInfo <int, string, StringView>();
            int data     = new Random(21).Next();

            // Call
            StringView view = viewInfo.CreateInstance(data);

            // Assert
            Assert.IsNotNull(view);
            Assert.IsNull(view.Data);
        }
示例#29
0
        public static unsafe void Format(StringBuffer formatter, TimeSpan timeSpan, StringView format)
        {
            var   tempCharsLength = 3;
            char *tempChars       = stackalloc char[tempCharsLength];

            AppendNumber(formatter, timeSpan.Hours, 2, tempChars, tempCharsLength);
            formatter.Append(':');
            AppendNumber(formatter, timeSpan.Minutes, 2, tempChars, tempCharsLength);
            formatter.Append(':');
            AppendNumber(formatter, timeSpan.Seconds, 2, tempChars, tempCharsLength);
            formatter.Append('.');
            AppendNumber(formatter, timeSpan.Milliseconds, 3, tempChars, tempCharsLength);
        }
 public SearchExpressionEvaluatorException(string message, StringView errorPosition, SearchExpressionContext c, Exception innerException = null)
     : base(FormatDefaultEvaluationExceptionMessage(c, message), innerException)
 {
     if (errorPosition.IsNullOrEmpty())
     {
         errorView = new StringView(c.search.searchText);
     }
     else
     {
         errorView = errorPosition;
     }
     evaluationContext = c;
 }
示例#31
0
        public void TestVariableSetting()
        {
            // Test that the default status is zero and that message propogates
            StringView view = new StringView("This is my message");

            Assert.AreEqual("This is my message", view.Output);
            Assert.AreEqual(0, view.StatusCode);

            // Test that sending a status code propogates
            view = new StringView("This is another message", 1);
            Assert.AreEqual("This is another message", view.Output);
            Assert.AreEqual(1, view.StatusCode);
        }
示例#32
0
        /// <summary>
        /// Adds a new URL pattern with a static URL.
        /// </summary>
        public void AddStaticStringView(string url, StringView view)
        {
            if (!url.StartsWith("/"))
                url = "/" + url;

            AddView("^" + Regex.Escape(url) + "$", StringToVoidView(view));
        }
示例#33
0
 public void AddStringView(string pattern, StringView view) { urlPatterns.Add(new UrlPattern(pattern, StringToVoidView(view))); }