public static int FindByPath(ItemTree tree, StringStore strings, string path, char delimiter = '\\') { String8 path8 = String8.Convert(path, new byte[String8.GetLength(path)]); String8Set pathSplit8 = path8.Split(delimiter, new int[String8Set.GetLength(path8, delimiter)]); return(tree.FindByPath(0, pathSplit8, strings)); }
public void String8_ShiftBack() { String8Block block = new String8Block(); // Goal: Split on semi-colon, collapse semi-colon and spaces in-place String8 shiftable = "One; Two;Three; Four".TestConvert(); int totalShift = 0; String8Set parts = shiftable.Split(UTF8.Semicolon, new PartialArray <int>(5, false)); for (int i = 0; i < parts.Count; ++i) { String8 part = parts[i]; totalShift++; if (part.StartsWith(UTF8.Space)) { part = part.Substring(1); totalShift++; } String8 beforeShift = block.GetCopy(part); String8 shifted = part.ShiftBack(totalShift); Assert.AreEqual(beforeShift, shifted); } String8 result = shiftable.Substring(0, shiftable.Length - totalShift); Assert.AreNotEqual("OneTwoThreeFour", result.ToString()); }
private String8Set SplitRows(String8 block, PartialArray <int> rowPositionArray) { // Split the block into lines (and save the split for use splitting columns) _blockLines = block.Split(UTF8.Newline, _lineArray); // Reset where which line the next row begins with _nextLineIndex = 0; rowPositionArray.Clear(); rowPositionArray.Add(0); for (int i = 0; i < _blockLines.Count - 1; ++i) { String8 line = _blockLines[i]; // An empty line (or \n\r\n) indicates a new logical row if (line.Length == 0 || (line.Length == 1 && line[0] == UTF8.CR)) { rowPositionArray.Add(_lineArray[i + 1]); } } rowPositionArray.Add(block.Length + 1); return(new String8Set(block, 1, rowPositionArray)); }
private string SplitAndJoin(string value, byte delimiter) { String8 value8 = String8.Convert(value, new byte[String8.GetLength(value)]); String8Set set = value8.Split(delimiter, new PartialArray <int>()); String8 joined8 = set.Join(UTF8.Pipe, new byte[set.Value.Length]); return(joined8.ToString()); }
protected override String8Set SplitCells(String8 row, PartialArray <int> cellPositionArray) { // Remove trailing '\r' to handle '\r\n' and '\n' line endings uniformly if (row.EndsWith(UTF8.CR)) { row = row.Substring(0, row.Length - 1); } return(row.Split(UTF8.Tab, cellPositionArray)); }
public void AlphanumericSplitter_EndToEndPerformance() { String8 code = AllCodeText.AllCode8; String8Set set = default(String8Set); PartialArray <int> matchContainer = new PartialArray <int>(2048); HashSet <String8> uniqueWords = new HashSet <String8>(); StringStore strings = new StringStore(); MemberIndex index = new MemberIndex(); int iterations = 10; int totalWordsSplit = 0; // Split, Add, Index Goal: 30k per millisecond [30 MB/sec] Verify.PerformanceByBytes(30 * LongExtensions.Megabyte, () => { for (int iteration = 0; iteration < iterations; ++iteration) { String8Set codeByLine = code.Split(UTF8.Newline, new PartialArray <int>()); for (int lineIndex = 0; lineIndex < codeByLine.Count; ++lineIndex) { // Convert and Split the line String8 line = codeByLine[lineIndex]; set = AlphanumericSplitter.Split(line, ref matchContainer); totalWordsSplit += set.Count; if (set.Count > 0) { int matchIndex = AlphanumericSplitter.IsAlphaNumeric(set[0][0]) ? 0 : 1; for (; matchIndex < set.Count; matchIndex += 2) { // If the word is long enough... String8 word = set[matchIndex]; if (word.Length > 2) { if (!uniqueWords.Contains(word)) { int wordIdentifier = strings.FindOrAddString(word); uniqueWords.Add(strings[wordIdentifier]); index.AddItem(wordIdentifier, lineIndex); } } } } } } return(iterations * code.Length); }); }
public void String8Set_Split_Performance() { String8 list = String8.Convert("System.Collections.Generic.List<T>", new byte[50]); String8 noDelimiters = String8.Convert("No Delimiters", new byte[25]); PartialArray <int> partBuffer = new PartialArray <int>(10, false); // Goal: 256MB/sec [Surface Book i7] Verify.PerformanceByBytes(150 * LongExtensions.Megabyte, () => { int iterations = 200000; for (int iteration = 0; iteration < iterations; ++iteration) { list.Split(UTF8.Period, partBuffer); noDelimiters.Split(UTF8.Period, partBuffer); } return(iterations * (list.Length + noDelimiters.Length)); }); }
public void SetLocation(int memberIndex, string filePath, ushort line, ushort charInLine) { // TODO: Handle '/' or '\' in ItemTree to avoid canonicalizing if (!String.IsNullOrEmpty(filePath) && (filePath.StartsWith("http:", StringComparison.OrdinalIgnoreCase) || filePath.StartsWith("https:", StringComparison.OrdinalIgnoreCase))) { filePath = filePath.Replace('/', '\\'); } // Find (or add) the file path to the File Tree int fileIndex = 0; if (!String.IsNullOrEmpty(filePath)) { String8 path8 = String8.Convert(filePath, new byte[String8.GetLength(filePath)]); String8Set splitPath8 = path8.Split('\\', new int[String8Set.GetLength(path8, '\\')]); fileIndex = this.FileTree.AddPath(0, splitPath8, this.StringStore); } // Write the updated location SymbolLocation location; location.FileIndex = fileIndex; location.Line = line; location.CharInLine = charInLine; if (this.DeclaredMemberLocations.Count == memberIndex) { this.DeclaredMemberLocations.Add(location); } else if (this.DeclaredMemberLocations.Count > memberIndex) { this.DeclaredMemberLocations[memberIndex] = location; } else { throw new InvalidOperationException(String.Format(Resources.DatabaseArraysOutOfSync, "DeclaredMemberLocations")); } }
public MutableSymbol FindOrAddPath(string path, char delimiter, SymbolType pathPartType) { String8 path8 = String8.Convert(path, new byte[String8.GetLength(path)]); String8Set splitPath8 = path8.Split(delimiter, new int[String8Set.GetLength(path8, delimiter)]); int currentIndex = _index; for (int i = 0; i < splitPath8.Count; ++i) { String8 part = splitPath8[i]; int partNameIdentifier = _database.StringStore.FindOrAddString(part); int foundNode; if (!_database.DeclaredMembers.TryFindChildByName(currentIndex, partNameIdentifier, out foundNode)) { foundNode = _database.DeclaredMembers.Add(currentIndex, partNameIdentifier); _database.DeclaredMemberDetails.Add(new SymbolDetails() { Type = pathPartType }); _database.DeclaredMemberLocations.Add(default(SymbolLocation)); } currentIndex = foundNode; } return new MutableSymbol(_database, currentIndex); }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container) { //validate if (item == null) { return(DefaultTemplate); } //get string var str = item as string; if (item.GetType().IsPrimitive || item.GetType().IsEnum) { str = item.ToString(); } //select template if (str == null) { return(DefaultTemplate); } if (String1 != null && String1.Split(',').Contains(str)) { return(Template1); } if (String2 != null && String2.Split(',').Contains(str)) { return(Template2); } if (String3 != null && String3.Split(',').Contains(str)) { return(Template3); } if (String4 != null && String4.Split(',').Contains(str)) { return(Template4); } if (String5 != null && String5.Split(',').Contains(str)) { return(Template5); } if (String6 != null && String6.Split(',').Contains(str)) { return(Template6); } if (String7 != null && String7.Split(',').Contains(str)) { return(Template7); } if (String8 != null && String8.Split(',').Contains(str)) { return(Template8); } if (String9 != null && String9.Split(',').Contains(str)) { return(Template9); } if (String10 != null && String10.Split(',').Contains(str)) { return(Template10); } return(DefaultTemplate); }
protected override String8Set SplitRows(String8 block, PartialArray <int> rowPositionArray) { return(block.Split(UTF8.Newline, rowPositionArray)); }
public MutableSymbol FindByFullName(string path, char delimiter) { String8 path8 = String8.Convert(path, new byte[String8.GetLength(path)]); String8Set splitPath8 = path8.Split(delimiter, new int[String8Set.GetLength(path8, delimiter)]); return new MutableSymbol(_database, _database.DeclaredMembers.FindByPath(_index, splitPath8, _database.StringStore)); }