///// <summary> ///// 字符替换 ///// </summary> ///// <param name="value">原字符</param> ///// <param name="replaceChar">替换后的字符</param> //public void Replace(char value, char replaceChar) //{ // if (Length != 0) // { // fixed (char* valueFixed = String) // { // char* start = valueFixed + StartIndex, end = start + Length; // if (*--end == value) // { // do // { // while (*start != value) ++start; // *start = replaceChar; // if (start == end) return; // ++start; // } // while (true); // } // while (start != end) // { // if (*start == value) *start = replaceChar; // ++start; // } // } // } //} /// <summary> /// 分割字符串 /// </summary> /// <param name="split">分割符</param> /// <returns>字符子串集合</returns> public LeftArray <SubString> Split(char split) { LeftArray <SubString> values = default(LeftArray <SubString>); if (String != null) { fixed(char *valueFixed = String) { char *last = valueFixed + Start, end = last + Length; for (char *start = last; start != end;) { if (*start == split) { values.PrepLength(1); values.Array[values.Length++].Set(String, (int)(last - valueFixed), (int)(start - last)); last = ++start; } else { ++start; } } values.PrepLength(1); values.Array[values.Length++].Set(String, (int)(last - valueFixed), (int)(end - last)); } } return(values); }
public void CallDeSerialize(ref Node value) { space(); if (State != DeSerializeState.Success) { return; } if (*current == '<') { char code = *(current + 1); if (((bits[code & 0xff] & targetStartCheckBit) | (code & 0xff00)) == 0) { if (code == '/') { value.SetString(string.Empty); return; } if (code == '!') { searchCData2(); if (State == DeSerializeState.Success) { value.SetString(xml, (int)(valueStart - xmlFixed), valueSize); } return; } State = DeSerializeState.NotFoundTagStart; return; } char *nameStart; LeftArray <KeyValue <SubString, Node> > nodes = new LeftArray <KeyValue <SubString, Node> >(0); KeyValue <Range, Range>[] attributes; int nameSize = 0; do { nameStart = getName(ref nameSize); if (State != DeSerializeState.Success) { return; } if (nameStart == null) { value.SetNode(ref nodes); return; } nodes.PrepLength(1); nodes.Array[nodes.Length].Key.Set(xml, (int)(nameStart - xmlFixed), nameSize); attributes = Config.IsAttribute && this.attributes.Length != 0 ? this.attributes.GetArray() : null; if (isTagEnd == 0) { CallDeSerialize(ref nodes.Array[nodes.Length].Value); if (State != DeSerializeState.Success || CheckNameEnd(nameStart, nameSize) == 0) { return; } } if (attributes != null) { nodes.Array[nodes.Length].Value.SetAttribute(xml, attributes); } ++nodes.Length; }while (true); } else { valueStart = current; value.Type = NodeType.String; do { if (*current == '<') { value.String.Set(xml, (int)(valueStart - xmlFixed), (int)(endSpace() - valueStart)); if (Config.IsTempString && value.Type == NodeType.EncodeString) { value.Type = NodeType.TempString; } return; } if (*current == '&') { value.Type = NodeType.EncodeString; while (*++current != ';') { if (*current == '<') { State = DeSerializeState.DecodeError; return; } } } ++current; }while (true); } }