private static ushort GetFreeIndex(SerializationInfo info) { HashSet <ushort> indexes = new HashSet <ushort>(); foreach (SerializationEntry entry in info) { Match m = IDRegex.Match(entry.Name); if (!m.Success) { continue; } if (ushort.TryParse(m.Groups[IndexGroup].Value, out ushort result)) { indexes.Add(result); } } for (ushort index = 0; index <= ushort.MaxValue; index++) { if (!indexes.Contains(index)) { return(index); } } throw new InvalidOperationException(); }
private void eventIDsText_TextChanged(object sender, EventArgs e) { if (!internalSet) { bool match = false; if (eventIDsText.TextLength == 0 || (match = IDRegex.IsMatch(eventIDsText.Text)) || string.Equals(eventIDsText.Text, eventIDsText.Tag)) { errorProvider.SetError(eventIDsText, String.Empty); if (match) { ql.Query.IDString = eventIDsText.Text; } } else { errorProvider.SetError(eventIDsText, EditorProperties.Resources.Error_EventTriggerIDInvalid); } } }
/// <summary> /// 指定したResSetを /// 設定されているスキンを使用して文字列形式に変換 /// </summary> /// <param name="resSet"></param> /// <returns></returns> public override string Convert(ResSet resSet) { if (!resSet.Visible) { return(String.Empty); } if (resSet.DateString == "透明あぼーん") { return(String.Empty); } /* * if (resSet.IsABone) { * resSet = ResSet.ABone(resSet, ABoneType.NG, ""); * resSet.Email = String.Empty; * }*/ // 使用するスキン string skinhtml = resSet.IsNew ? newResSkin : resSkin; string dateonly, body; // 本分からtagを取り除く body = resSet.Body; body = Regex.Replace(body, "<a[^>]+>(?<uri>[^<]*)</a>", "${uri}", RegexOptions.IgnoreCase); body = Regex.Replace(body, "<(?!br|hr)[^>]+>", ""); buffer.Append(body); buffer.Replace("<br>", "\r\n"); buffer.Replace("<hr>", "\r\n ————————————————————\r\n"); buffer.Replace(">", ">"); buffer.Replace("<", "<"); body = buffer.ToString(); buffer.Remove(0, buffer.Length); #region 日付とIDを作成 dateonly = resSet.DateString; Match m = Regex.Match(resSet.DateString, "( ID:)|(\\[)"); if (m.Success) { dateonly = resSet.DateString.Substring(0, m.Index); } #endregion #if REGEX_REPLACE skinhtml = PlainNumberRegex.Replace(skinhtml, resSet.Index.ToString()); skinhtml = IDRegex.Replace(skinhtml, resSet.ID); skinhtml = NameRegex.Replace(skinhtml, resSet.Name); skinhtml = EmailRegex.Replace(skinhtml, resSet.Email); skinhtml = DateRegex.Replace(skinhtml, resSet.DateString); skinhtml = DateOnlyRegex.Replace(skinhtml, dateonly); skinhtml = BodyRegex.Replace(skinhtml, body); #else buffer.Append(skinhtml); buffer.Replace("<PLAINNUMBER/>", resSet.Index.ToString()); buffer.Replace("<ID/>", resSet.ID); buffer.Replace("<NAME/>", HtmlTextUtility.RemoveTag(resSet.Name)); buffer.Replace("<MAIL/>", resSet.Email); buffer.Replace("<DATE/>", resSet.DateString); buffer.Replace("<DATEONLY/>", dateonly); buffer.Replace("<MESSAGE/>", body); skinhtml = buffer.ToString(); buffer.Remove(0, buffer.Length); #endif return(skinhtml); }
private static void GetId(SerializationInfo info, out ulong id, out ushort index, out bool reference) { HashSet <ushort> indexes = new HashSet <ushort>(); HashSet <ushort> ref_values = new HashSet <ushort>(); foreach (SerializationEntry entry in info) { Match m = IDRegex.Match(entry.Name); if (!m.Success) { continue; } if (ushort.TryParse(m.Groups[IndexGroup].Value, out ushort result)) { if (m.Groups[RefGroup].Success) { ref_values.Add(result); } else { indexes.Add(result); } } } id = 1; reference = false; for (index = 0; index <= ushort.MaxValue; index++) { if (!indexes.Contains(index)) { break; } if (index == ushort.MaxValue) { throw new InvalidOperationException(); } } for (; index >= 0; index--) { try { if (!ref_values.Contains(index)) { if (index == 0) { break; } continue; } id = info.GetUInt64(IDPrefix + index); reference = info.GetBoolean(IDPrefix + index + RefSuffix); } catch (InvalidCastException) { id = 1; if (index == 0) { break; // Don't run third addition } } } }