/// <summary> /// 文本转HTML /// </summary> /// <param name="value">文本值</param> /// <param name="stream">HTML编码流</param> public unsafe void ToHtml(ref subString value, unmanagedStream stream) { if (value.Length != 0) { if (stream == null) { log.Error.Throw(log.exceptionType.Null); } int length = value.Length; fixed(char *valueFixed = value.value) { char *start = valueFixed + value.StartIndex, end = start + length; int count = encodeCount(start, end); if (count == 0) { stream.PrepLength(length <<= 1); unsafer.memory.Copy(start, stream.CurrentData, length); } else { length += count << 2; stream.PrepLength(length <<= 1); toHtml(start, end, (char *)stream.CurrentData); } stream.UnsafeAddLength(length); } } }
public unsafe void LeftRightMatchs(ref subString text, list <keyValue <int, int> > matchs) { if (text != null && text.Length != 0 && matchs != null) { leftRightMatchs(ref text, matchs); } }
/// <summary> /// 从左到右最大匹配 /// </summary> /// <param name="text">匹配文本</param> /// <param name="matchs">匹配结果集合</param> private unsafe void leftRightMatchs(ref subString text, list <keyValue <int, int> > matchs) { node[] pool = NodePool; Dictionary <char, int> bootNode = pool[boot].Nodes; string value; int node = boot, nextNode = 0, index = text.StartIndex - 1, matchCount; fixed(char *valueFixed = text.Value) { for (char *start = valueFixed + text.StartIndex, end = start + text.Length; start != end; ++start) { char letter = *start; if (pool[node].GetLinkWhereNull(letter, ref nextNode, ref node) != 0) { while (node != 0) { int isGetValue = pool[node].GetNodeOrLink(letter, ref nextNode, ref node, out value); if (value != null) { matchCount = matchs.Count; matchs.AddLength(); matchs.UnsafeArray[matchCount].Set(index - value.Length + 1, value.Length); } if (isGetValue == 0) { break; } } if (node == 0 && !bootNode.TryGetValue(letter, out nextNode)) { nextNode = boot; } } ++index; if ((value = pool[node = nextNode].Value) != null) { matchCount = matchs.Count; matchs.AddLength(); matchs.UnsafeArray[matchCount].Set(index - value.Length + 1, value.Length); } } } node = pool[node].Link; while (node != 0) { if ((value = pool[node].GetLink(ref node)) != null) { matchCount = matchs.Count; matchs.AddLength(); matchs.UnsafeArray[matchCount].Set(index - value.Length + 1, value.Length); } } }
/// <summary> /// 格式化样式表 /// </summary> /// <param name="style">样式表</param> /// <returns>样式表</returns> private static unsafe string formatStyle(string style) { if (style != null) { Dictionary <subString, subString> values = dictionary.CreateSubString <subString>(); foreach (subString value in style.split(';')) { int index = value.IndexOf(':'); if (index != -1) { subString name = value.Substring(0, index).toLower(); //showjim 修改为数组索引模式 if (fastCSharp.web.html.SafeStyleAttributes.Contains(name.ToString())) { values[name] = value.Substring(++index); } } } if (values.Count != 0) { int length = (values.Count << 1) - 1; foreach (KeyValuePair <subString, subString> value in values) { length += value.Key.Length + value.Value.Length; } string newStyle = fastCSharp.String.FastAllocateString(length); byte * bits = htmlNode.Bits.Byte; fixed(char *newStyleFixed = newStyle, styleFixed = style) { char *write = newStyleFixed; foreach (KeyValuePair <subString, subString> value in values) { if (write != newStyleFixed) { *write++ = ';'; } for (char *start = styleFixed + value.Key.StartIndex, end = start + value.Key.Length; start != end; *write++ = *start++) { ; } *write++ = ':'; for (char *start = styleFixed + value.Value.StartIndex, end = start + value.Value.Length; start != end; ++start) { *write++ = ((bits[*(byte *)start] & htmlNode.CssFilterBit) | *(((byte *)start) + 1)) == 0 ? ' ' : *start; } } } return(newStyle); } } return(null); }
public unsafe bool IsMatchLess(ref subString values) { if (values.Length != 0) { fixed(char *valueFixed = values.Value) { char *start = valueFixed + values.StartIndex; return(isMatchLess(start, start + values.Length)); } } return(false); }
/// <summary> /// 分解成员名称 /// </summary> /// <param name="memberName">成员名称</param> /// <returns>成员名称集合</returns> protected static subString[] splitMemberName(string memberName) { int memberIndex = 0; while (memberIndex != memberName.Length && memberName[memberIndex] == '.') { ++memberIndex; } string value = memberName.Substring(0, memberIndex); subString[] names = new subString(memberName, memberIndex).Split('.').ToArray(); names[0] = value + names[0]; return(names); }
/// <summary> /// 字符串 /// </summary> /// <param name="value">字符串</param> /// <param name="jsonStream">JSON输出流</param> public static void ToString(ref subString value, charStream jsonStream) { if (value.value == null) { WriteNull(jsonStream); } else { jsonStream.PrepLength(value.Length + 2); jsonStream.UnsafeWrite(Quote); jsonStream.Write(ref value); jsonStream.UnsafeWrite(Quote); } }
/// <summary> /// 对账单数据名称检测 /// </summary> /// <param name="names"></param> /// <param name="type"></param> /// <returns></returns> internal static bool CheckName(subString names, billType type) { switch (type) { case billType.ALL: return(names.Equals("交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,微信退款单号,商户退款单号,退款金额,代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率")); case billType.SUCCESS: return(names.Equals("交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,商品名称,商户数据包,手续费,费率")); case billType.REFUND: return(names.Equals("交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率")); } return(false); }
/// <summary> /// 根据提交类型获取编码字符集 /// </summary> /// <param name="contentType">提交类型</param> /// <returns>编码字符集</returns> private static Encoding getEncoding(string contentType) { foreach (subString value in contentType.Split(';')) { subString key = value.Trim(); if (key.StartsWith(webClient.CharsetName)) { try { Encoding encoding = Encoding.GetEncoding(key.Substring(webClient.CharsetName.Length)); return(encoding); } catch { } } } return(null); }
/// <summary> /// 加载数据记录 /// </summary> /// <param name="name">名称</param> /// <param name="node"></param> public void LoadMember(subString name, xmlNode node) {//https://msdn.microsoft.com/zh-cn/library/fsbx0t7x(v=vs.80).aspx //对于泛型类型,类型名称后跟反勾号,再跟一个数字,指示泛型类型参数的个数。例如, //<member name="T:SampleClass`2"> 是定义为 public class SampleClass<T, U> 的类型的标记。 if (name[1] == ':') { char code = name[0]; switch (code & 7) { case 'T' & 7: //类型:类、接口、结构、枚举、委托 if (code == 'T') { types[name.Substring(2)] = node; } break; case 'F' & 7: //字段 if (code == 'F') { fields[name.Substring(2)] = node; } break; case 'P' & 7: //属性(包括索引程序或其他索引属性) if (code == 'P') { properties[name.Substring(2)] = node; } break; case 'M' & 7: //方法(包括一些特殊方法,例如构造函数、运算符等) if (code == 'M') { methods[name.Substring(2)] = node; } break; //case 'E' & 7://事件 // break; //case 'N' & 7://命名空间 //case '!' & 7://错误字符串 //break; } } }
/// <summary> /// 文本转HTML /// </summary> /// <param name="value">文本值</param> /// <returns>HTML编码</returns> public unsafe void ToHtml(ref subString value) { if (value.Length != 0) { int length = value.Length; fixed(char *valueFixed = value.value) { char *start = valueFixed + value.StartIndex, end = start + length; int count = encodeCount(start, end); if (count != 0) { string newValue = fastCSharp.String.FastAllocateString(length += count << 2); fixed(char *data = newValue) toHtml(start, end, data); value.UnsafeSet(newValue, 0, newValue.Length); } } } }
public object getValor(Entorno.Entorno ent) { if (ent.existe(variable)) { Simbolo sim = ent.get(variable); Object valor = sim.valor; foreach (Expresion exp in this.fuciones) { if (exp is Contiene) { Contiene exp2 = (Contiene)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Insertar) { Insertar exp2 = (Insertar)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Obtener) { Obtener exp2 = (Obtener)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Poner) { Poner exp2 = (Poner)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Remover) { Remover exp2 = (Remover)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Size) { Size exp2 = (Size)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is Vaciar) { Vaciar exp2 = (Vaciar)exp; exp2.coleccion = valor; valor = exp2.getValor(ent); } else if (exp is endWith) { endWith exp2 = (endWith)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is length) { length exp2 = (length)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is startsWith) { startsWith exp2 = (startsWith)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is subString) { subString exp2 = (subString)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is toLower) { toLower exp2 = (toLower)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is toUpper) { toUpper exp2 = (toUpper)exp; exp2.cadena = valor; valor = exp2.getValor(ent); } else if (exp is getDay) { getDay exp2 = (getDay)exp; exp2.fecha = valor; valor = exp2.getValor(ent); } else if (exp is getMonth) { getMonth exp2 = (getMonth)exp; exp2.fecha = valor; valor = exp2.getValor(ent); } else if (exp is getYear) { getYear exp2 = (getYear)exp; exp2.fecha = valor; valor = exp2.getValor(ent); } else if (exp is getHour) { getHour exp2 = (getHour)exp; exp2.hora = valor; valor = exp2.getValor(ent); } else if (exp is getMinuts) { getMinuts exp2 = (getMinuts)exp; exp2.hora = valor; valor = exp2.getValor(ent); } else if (exp is getSeconds) { getSeconds exp2 = (getSeconds)exp; exp2.hora = valor; valor = exp2.getValor(ent); } else if (exp is Identificador) { if (valor is Objeto) { Objeto ob = (Objeto)valor; Identificador ide = (Identificador)exp; valor = ide.getValor(ob.atributos); } } } return(valor); } return(null); }
/// <summary> /// 对账单统计数据 /// </summary> /// <param name="names"></param> /// <returns></returns> internal static bool CheckName(subString names) { return(names.Equals("总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额")); }
public static byte[] GetContentType(ref subString extensionName) { return(contentTypes.Get(ref extensionName, unknownContentType)); }
/// <summary> /// 加载配置文件 /// </summary> /// <param name="file">配置文件</param> private unsafe void load(FileInfo file) { if (file.Exists) { string fileName = file.FullName.fileNameToLower(); int count = files.length; if (count != 0) { foreach (string name in files.array) { if (errors.length == 0) { if (name == fileName) { errors.Add("配置文件循环嵌套"); errors.Add(name); } } else { errors.Add(name); } if (--count == 0) { break; } } if (errors.length != 0) { log.Error.Real(errors.joinString(@" "), new System.Diagnostics.StackFrame(), false); errors.Empty(); } } string config = File.ReadAllText(fileName, appSetting.Encoding); fixed(char *configFixed = config) { for (char *current = configFixed, end = configFixed + config.Length; current != end;) { char *start = current; while (*current != '=' && ++current != end) { ; } if (current == end) { break; } subString name = subString.Unsafe(config, (int)(start - configFixed), (int)(current - start)); if (name.Equals(appSetting.ConfigIncludeName)) { for (start = ++current; current != end && *current != '\n'; ++current) { ; } Load(Path.Combine(file.DirectoryName, config.Substring((int)(start - configFixed), (int)(current - start)).Trim())); if (current == end) { break; } ++current; } else { for (start = ++current; current != end; ++current) { if (*current == '\n') { while (++current != end && *current == '\n') { ; } if (current == end) { break; } if (*current != '\t' && *current != ' ') { break; } } } hashString nameKey = name; if (configs.ContainsKey(nameKey)) { log.Error.Real("重复的配置名称 : " + name.ToString(), new System.Diagnostics.StackFrame(), false); } else { configs.Add(nameKey, subString.Unsafe(config, (int)(start - configFixed), (int)(current - start))); } } } } } else { log.Default.Real("找不到配置文件 : " + file.FullName, new System.Diagnostics.StackFrame(), false); } }
/// <summary> /// 文本分词 /// </summary> /// <param name="text">文本</param> /// <param name="length">文本长度</param> /// <returns>分词结果</returns> private unsafe list <subString> getWords(string text, int length) { fixed(char *textFixed = text) { simplified.Format(textFixed, length); int count = (length + 7) >> 3; byte * match = stackalloc byte[count]; fixedMap matchMap = new fixedMap(match, count, 0); list <subString> words = typePool <list <subString> > .Pop(); if (words == null) { words = new list <subString>(); } else if (words.Count != 0) { words.Clear(); } list <keyValue <int, int> > matchs = typePool <list <keyValue <int, int> > > .Pop() ?? new list <keyValue <int, int> >(); byte * charTypes = charTypePointer.Byte; subString matchWord = default(subString); for (char *start = textFixed, end = textFixed + length; start != end;) { if (*start == ' ') { *end = '?'; while (*++start == ' ') { ; } } else { * end = ' '; char *segment = start; if ((uint)(*start - 0x4E00) <= 0X9FA5 - 0x4E00) { while ((uint)(*++start - 0x4E00) <= 0X9FA5 - 0x4E00) { ; } if ((length = (int)(start - segment)) == 1) { words.Add(subString.Unsafe(text, (int)(segment - textFixed), 1)); } else { int startIndex = (int)(segment - textFixed); matchs.Empty(); matchWord.UnsafeSet(text, startIndex, length); wordTrieGraph.LeftRightMatchs(ref matchWord, matchs); if ((count = matchs.Count) != 0) { foreach (keyValue <int, int> value in matchs.UnsafeArray) { words.Add(subString.Unsafe(text, value.Key, value.Value)); matchMap.Set(value.Key, value.Value); if (--count == 0) { break; } } } int index = startIndex; for (int endIndex = startIndex + length; index != endIndex; ++index) { if (matchMap.Get(index)) { if ((count = index - startIndex) != 1) { words.Add(subString.Unsafe(text, startIndex, count)); } startIndex = index; } else { words.Add(subString.Unsafe(text, index, 1)); } } if ((index -= startIndex) > 1) { words.Add(subString.Unsafe(text, startIndex, index)); } } } else { byte type = charTypes[*start]; if (type == (byte)charType.OtherLetter) { while (charTypes[*++start] == (byte)charType.OtherLetter) { ; } } else { char *word = start; for (byte newType = charTypes[*++start]; newType >= (byte)charType.Letter; newType = charTypes[*++start]) { if (type != newType) { if (type != (byte)charType.Keep) { words.Add(subString.Unsafe(text, (int)(word - textFixed), (int)(start - word))); } type = newType; word = start; } } } words.Add(subString.Unsafe(text, (int)(segment - textFixed), (int)(start - segment))); } } } typePool <list <keyValue <int, int> > > .PushNotNull(matchs); if ((count = words.Count) == 0) { typePool <list <subString> > .PushNotNull(words); return(null); } return(words); } }