public String2[] Split(String2 source) { if (source.Length < 1) { throw new ArgumentNullException("The length of split for source is short."); } if (Length < source.Length) { return(new String2[] { Copy() }); } int count = 0; int pre = 0; int peek = 0; String2LinkNode fin = new String2LinkNode(); String2LinkNode node = fin; while ((peek = IndexOf(source, pre)) > -1) { node = node.Add(SubString(pre, peek - pre)); pre = peek + source.Length; count++; } node = node.Add(SubString(pre, Length - pre)); String2[] ret = new String2[count + 1]; for (int i = 0; i < ret.Length; i++) { ret[i] = fin.Data; fin = fin.Next; } return(ret); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (!(obj is String2)) { return(false); } String2 temp = obj as String2; if (Length != temp.Length) { return(false); } for (int i = 0; i < Length; i++) { if (this[i] != temp[i]) { return(false); } } return(true); }
public String2 Replace(String2 oldVal, String2 newVal) { if (oldVal.Length < 1) { throw new ArgumentNullException("Replace"); } if (Length < oldVal.Length) { return(Copy()); } int pre = 0; int peek = 0; String2LinkNode fin = new String2LinkNode(); String2LinkNode node = fin; while ((peek = IndexOf(oldVal, pre)) > -1) { node = node.Add(SubString(pre, peek - pre)); node = node.Add(newVal); pre = peek + oldVal.Length + 1; } node = node.Add(SubString(pre, Length - pre)); String2 ret = fin.Data; while (fin.Next != null) { fin = fin.Next; if (fin.IsNull()) { break; } ret += fin.Data; } return(ret); }
public void SetHeader(String2 key, String2 value) { if (this.Headers.ContainsKey(key)) { this.Headers.Remove(key); } this.Headers.Add(key, value); }
public Response() { Version = "HTTP/1.1"; State = "403"; StateComment = "Not Found"; ContextType = "text/html; charset=UTF-8"; _header.Add("Server", "MyServer"); _header.Add("Cache-Control", "no-cache"); Body = ""; }
public Request(String2 header) { header = header.Trim(); String2[] temp_header = header.Split(new String2("\r\n")); String2 state = temp_header[0]; String2[] temp_state = state.Split(" "); Method = temp_state[0].Trim(); Uri = temp_state[1].Trim(); int pos = Uri.IndexOf("?"); if (pos > -1) { String2 temp_uri = Uri.SubString(pos + 1, Uri.Length - (pos + 1)).Trim(); Uri = Uri.SubString(0, pos).Trim(); String2[] temp_query_string = temp_uri.Split("&"); foreach (var t in temp_query_string) { pos = t.IndexOf("="); if (pos < 0) { continue; } String2 key = t.SubString(0, pos).Trim(); String2 value = t.SubString(pos + 1, t.Length - (pos + 1)).Trim(); if (_query_string.ContainsKey(key)) { _query_string.Remove(key); } _query_string.Add(key, value); } } Version = temp_state[2].Trim(); for (int i = 1; i < temp_header.Length; i++) { pos = temp_header[i].IndexOf(":"); if (pos < 0) { continue; } String2 key = temp_header[i].SubString(0, pos).Trim(); String2 value = temp_header[i].SubString(pos + 1, temp_header[i].Length - (pos + 1)).Trim(); if (_header.ContainsKey(key)) { _header.Remove(key); } _header.Add(key, value); } }
public int IndexLastOf(String2 source) { if (source.Length < 1) { return(-1); } if (Length < source.Length) { return(-1); } for (int i = Length - source.Length - 1; i >= 0; i--) { if (String2.CheckByte(data, i, source.ToBytes(), 0, source.Length)) { return(i); } } return(-1); }
public int IndexOf(String2 source, int index) { if (source.Length < 1) { return(-1); } if (Length < source.Length + index) { return(-1); } for (int i = index; i <= Length - source.Length; i++) { if (String2.CheckByte(data, i, source.ToBytes(), 0, source.Length)) { return(i); } } return(-1); }
public String2 ReadFile(String filepath) { FileInfo info = new FileInfo(filepath); if (!info.Exists) { throw new Exception("not file"); } if (".JS".Equals(info.Extension.ToUpper())) { ContextType = "text/javascript; charset=UTF-8"; } if (".CSS".Equals(info.Extension.ToUpper())) { ContextType = "text/css; charset=UTF-8"; } using (FileStream stream = new FileStream(info.FullName, FileMode.Open, FileAccess.Read)) { _body = new String2((int)info.Length); stream.Read(_body.ToBytes(), 0, (int)info.Length); } StateOK(); return(_body); }
public String2 ToBinary() { String2 ret = new String2(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Encode); for (int i = 0; i < 0x10; i++) { ret += String.Format(" 0x{0:X2}", i); } ret += CRLF; for (int i = 1, j = 0x00; i < Length; i++, j += 0x10) { --i; bool header = true; ret += CRLF; ret += String.Format("0x{0:X2} ", j); for (; i < Length && (i % 0x10 == 0 && !header); i++) { ret += String.Format("0x{0:X2}", this[i]); header = false; } } ret += CRLF; return(ret); }
public void SetResponseCode(int code, String2 comment) { State = String.Format("{0}", code); StateComment = comment; }
public int IndexOf(String2 source) { return(IndexOf(source, 0)); }
public bool CheckEnd(String2 separator) { return(CheckEnd(separator.ToBytes())); }
public String2LinkNode Add(String2 data) { this.data = data; this.next = new String2LinkNode(); return(this.next); }