public string GetRewriteUrl(Dictionary <string, string> parameters) { if (parameters.Count == 0 || !HasRewriteParamters) { return(Rewrite); } else { var buffer = HttpParse.GetCharBuffer(); int count = 0; int nameIndex = 0; ReadOnlySpan <char> str = Rewrite; for (int i = 0; i < str.Length; i++) { if (str[i] == '{') { nameIndex = i + 1; } else if (str[i] == '}') { if (nameIndex > 0) { string name = new string(str.Slice(nameIndex, i - nameIndex)); if (parameters.TryGetValue(name, out string value)) { for (int l = 0; l < value.Length; l++) { buffer[count] = value[l]; count++; } } } nameIndex = 0; } else { if (nameIndex == 0) { buffer[count] = str[i]; count++; } } } return(new string(buffer, 0, count)); } }
public static ReadOnlySpan <char> ReadCharLine(IndexOfResult result) { int offset = 0; char[] data = HttpParse.GetCharBuffer(); IMemoryBlock memory = result.Start; for (int i = result.StartPostion; i < memory.Length; i++) { data[offset] = (char)result.Start.Bytes[i]; offset++; if (offset == result.Length) { break; } } if (offset < result.Length) { Next: memory = result.Start.NextMemory; int count; if (memory.ID == result.End.ID) { count = result.EndPostion + 1; } else { count = memory.Length; } for (int i = 0; i < count; i++) { data[offset] = (char)memory.Bytes[i]; offset++; if (offset == result.Length) { break; } } if (offset < result.Length) { goto Next; } } return(new ReadOnlySpan <char>(data, 0, result.Length - 2)); }