private SplitState GetSplitState( LiveSplitState state, TimeSpan?timeDifference, int splitNumber, string comparison, TimingMethod method) { SplitState splitState = SplitState.Unknown; if (splitNumber < 0) { return(splitState); } if (timeDifference != null) { if (timeDifference < TimeSpan.Zero) { splitState = SplitState.AheadGaining; var lastDelta = LiveSplitStateHelper.GetLastDelta(state, splitNumber - 1, comparison, method); if (splitNumber > 0 && lastDelta != null && timeDifference > lastDelta) { splitState = SplitState.AheadLosing; } } else { splitState = SplitState.BehindLosing; var lastDelta = LiveSplitStateHelper.GetLastDelta(state, splitNumber - 1, comparison, method); if (splitNumber > 0 && lastDelta != null && timeDifference < lastDelta) { splitState = SplitState.BehindGaining; } } } if (LiveSplitStateHelper.CheckBestSegment(state, splitNumber, method)) { splitState = SplitState.BestSegment; } return(splitState); }
protected internal override void KeyBindDown(GUIBoundKeyEventArgs args) { base.KeyBindDown(args); if (ResizeMode == SplitResizeMode.NotResizable) { return; } if (_dragging || args.Function != EngineKeyFunctions.UIClick) { return; } if (CanDragAt(args.RelativePosition)) { _dragging = true; _splitState = SplitState.Manual; } }
public void TableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows, int rowStart, PdfContentByte[] canvases) { //If a split happened and we're on the next page if (this.currentSplitState.HasFlag(SplitState.DrawOnThisPage)) { //Draw something, nothing too special here var cb = canvases[PdfPTable.TEXTCANVAS]; cb.BeginText(); cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false), 18); //Use the table's widths and heights to find a spot, this probably could use some tweaking cb.SetTextMatrix(widths[0][0], heights[0]); cb.ShowText("A Split Happened!"); cb.EndText(); //Unset the draw on this page flag, it will be reset below if needed this.currentSplitState ^= SplitState.DrawOnThisPage; } //If we previously had the next page flag set change it to this page if (currentSplitState.HasFlag(SplitState.DrawOnNextPage)) { this.currentSplitState = SplitState.DrawOnThisPage; } }
private void ContentMouseMove(object sender, MouseEventArgs e) { state = (!Locked && ModifierKeys == Keys.Control) ? FixState() : SplitState.None; Cursor = state == SplitState.None ? Cursors.Default : splitCursor; }
/// <summary> /// Splits a string of bytes into lines. Each line is seperated by CR, LF, CR-LF or LF-CR, but CR-CR is considered two lines. /// </summary> /// <param name="input"></param> /// <param name="prevResults"></param> /// <returns></returns> public static SplitState SplitCRLF(IList <byte> input, SplitState state) { int nbytes = input.Count(); if (state.Lines == null) { state.Lines = new List <byte[]>(); } int start = 0; int nline = 0; bool appendNextLine = state.LastLinePartial; for (int i = 0; i < nbytes; i++) { var currChar = input[i]; var currIsCRorLF = currChar == (byte)'\r' || currChar == (byte)'\n'; if (state.lastWasUnusedCRorLF) { // When I see CR-CR or LF-LF then it's two lines // Handle the case of CR-CR-LF which is two lines if (currChar == state.lastChar) { if (appendNextLine) { state.AppendLine(input, start, start - 1); appendNextLine = false; } else { state.AddLine(input, start, start - 1); } nline++; state.lastWasUnusedCRorLF = true; } else if (currIsCRorLF) // e.g. CR LF or LF CR { // All of the CR and LF are used up. Next // CR or LF must be a new line. state.lastWasUnusedCRorLF = false; start = i + 1; } else // Is e.g. CR Q; the Q is the start of the next line. { start = i; state.lastWasUnusedCRorLF = false; } } else if (currIsCRorLF) { if (appendNextLine) { state.AppendLine(input, start, i - 1); appendNextLine = false; } else { state.AddLine(input, start, i - 1); // line is zero bytes long } nline++; state.lastWasUnusedCRorLF = true; } else { state.lastWasUnusedCRorLF = false; } state.lastChar = currChar; } if (state.lastWasUnusedCRorLF) { state.LastLinePartial = false; } else if (start >= input.Count) { // Ended exactly gracefully with CR LF or LF CR // Where there's a CR LF (or LF CR), the lastWasUnusedCRorLF is false because the last char LF (or CR) is used up. state.LastLinePartial = false; } else { // Have a bit more to add if (appendNextLine) { state.AppendLine(input, start, input.Count - 1); appendNextLine = false; } else { state.AddLine(input, start, input.Count - 1); } nline++; state.LastLinePartial = true; } return(state); }
public void ProcessSingleChar(char ch, char separator, bool trim) { switch (_currentState) { case SplitState.Start: if (ch == '"') { _currentState = SplitState.StartQuote; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch == ' ') { _currentState = SplitState.PotentialStartSpace; } else { _currentState = SplitState.Word; } break; case SplitState.StartQuote: if (ch == '"') { _currentState = SplitState.PotentialEndQuote; } else { _currentState = SplitState.EscapedWord; } break; case SplitState.StartSeparator: if (ch == '"') { _currentState = SplitState.StartQuote; } else if (ch == separator) { break; } else if (ch == ' ') { _currentState = SplitState.PotentialStartSpace; } else { _currentState = SplitState.Word; } break; case SplitState.PotentialStartSpace: if (ch == '"') { _currentState = SplitState.StartQuote; _sb.Length = 0; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch != ' ') { _currentState = SplitState.Word; } break; case SplitState.Word: // Allow quotes in the middle of a word. // a, b "b", c if (ch == '"') { //currentState = SplitState.UnescapedQuote; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } break; case SplitState.EscapedWord: if (ch == '"') { _currentState = SplitState.PotentialEndQuote; } break; case SplitState.PotentialEndQuote: if (ch == '"') { _currentState = SplitState.EscapedWord; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch == ' ') { _currentState = SplitState.PotentialEndSpace; } else { // Case where we had a double quote. like: // ""val" //_currentState = SplitState.UnescapedQuote; // Treat is as an escape. _currentState = SplitState.EscapedWord; } break; case SplitState.PotentialEndSpace: if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch != ' ') { _currentState = SplitState.UnescapedQuote; } // Anything else is a case like: "abc" d // does that parse as 'abc d'? Is it an error? break; default: break; } switch (_currentState) { case SplitState.StartSeparator: { PushValue(trim); } break; case SplitState.PotentialStartSpace: case SplitState.Word: case SplitState.EscapedWord: case SplitState.PotentialEndSpace: if (_captureValue) { _sb.Append(ch); } break; case SplitState.UnescapedQuote: throw new AssertException("unescaped double quote"); case SplitState.MissingEndQuote: throw new AssertException("missing closing quote"); } }
/// <summary> /// Splits method signature parameters into type names, resolves them and appends to a /// StringBuilder containing the resolved signature. /// </summary> /// <param name="parameters">The parameters to analyse.</param> /// <param name="signatureBuilder">The StringBuilder to append to.</param> private void SplitAndTranslateParameters(string module, string parameters, StringBuilder signatureBuilder) { // Input examples: // Abc, Ns.Ns.Def, Ns.Ghi/Jk // Abc<Xyz>, Def<X> // A<Xyz, !0, !!2>, Bcd, Ef // <a>bc, D // Ab, <c>d_efg<X, Y>, H SplitState state = SplitState.IdentifierStart; parameters = parameters.Trim() + " "; // Append input character that leads to final state int startIndex = 0; for (int i = 0; i < parameters.Length; i++) { char ch = parameters[i]; switch (state) { case SplitState.IdentifierStart: if (ch == ',' || ch == ' ') // Separator character { // No type name // Append separator character (if it's not the last) if (i < parameters.Length - 1) { signatureBuilder.Append(ch); } } else if (ch == '<') // Identifier starts with "<" { // Remember where the identifier started startIndex = i; state = SplitState.IdentifierAngles; } else // Normal identifier starts { // Remember where the identifier started startIndex = i; state = SplitState.Identifier; } break; case SplitState.IdentifierAngles: if (ch == ',' || ch == ' ') // Separator character { // This is unusual! Type names only start with "<" if they're compiler- // generated and those will also contain ">" afterwards. // Translate and append identifier string typeName = parameters.Substring(startIndex, i - startIndex); signatureBuilder.Append(TranslateTypeName(module, typeName)); // Append separator character (if it's not the last) if (i < parameters.Length - 1) { signatureBuilder.Append(ch); } state = SplitState.IdentifierStart; } else if (ch == '>') { state = SplitState.Identifier; } break; case SplitState.Identifier: if (ch == ',' || ch == ' ' || ch == '<' || ch == '>') // Separator character { // Translate and append identifier string typeName = parameters.Substring(startIndex, i - startIndex); signatureBuilder.Append(TranslateTypeName(module, typeName)); // Append separator character (if it's not the last) if (i < parameters.Length - 1) { signatureBuilder.Append(ch); } state = SplitState.IdentifierStart; } break; } } }
public static string[] split(string input, char separator, bool trim) { SplitState currentState = SplitState.Start; List <string> parts = new List <string>(); StringBuilder sb = new StringBuilder(); foreach (char ch in input) { switch (currentState) { case SplitState.Start: if (ch == '"') { currentState = SplitState.StartQuote; } else if (ch == separator) { currentState = SplitState.StartSeparator; } else if (ch == ' ') { currentState = SplitState.PotentialStartSpace; } else { currentState = SplitState.Word; } break; case SplitState.StartQuote: if (ch == '"') { currentState = SplitState.PotentialEndQuote; } else { currentState = SplitState.EscapedWord; } break; case SplitState.StartSeparator: if (ch == '"') { currentState = SplitState.StartQuote; } else if (ch == separator) { break; } else if (ch == ' ') { currentState = SplitState.PotentialStartSpace; } else { currentState = SplitState.Word; } break; case SplitState.PotentialStartSpace: if (ch == '"') { currentState = SplitState.StartQuote; sb.Length = 0; } else if (ch == separator) { currentState = SplitState.StartSeparator; } else if (ch != ' ') { currentState = SplitState.Word; } break; case SplitState.Word: if (ch == '"') { currentState = SplitState.UnescapedQuote; } else if (ch == separator) { currentState = SplitState.StartSeparator; } break; case SplitState.EscapedWord: if (ch == '"') { currentState = SplitState.PotentialEndQuote; } break; case SplitState.PotentialEndQuote: if (ch == '"') { currentState = SplitState.EscapedWord; } else if (ch == separator) { currentState = SplitState.StartSeparator; } else if (ch == ' ') { currentState = SplitState.PotentialEndSpace; } else { currentState = SplitState.UnescapedQuote; } break; case SplitState.PotentialEndSpace: if (ch == separator) { currentState = SplitState.StartSeparator; } else if (ch != ' ') { currentState = SplitState.UnescapedQuote; } break; default: break; } if (currentState == SplitState.StartSeparator) { string x = sb.ToString(); if (trim) { x = x.Trim(); } parts.Add(Intern(x)); sb.Length = 0; } if ((currentState == SplitState.PotentialStartSpace) || (currentState == SplitState.Word) || (currentState == SplitState.EscapedWord) || (currentState == SplitState.PotentialEndSpace)) { sb.Append(ch); } Utility.Assert(currentState != SplitState.UnescapedQuote, "unescaped double quote"); Utility.Assert(currentState != SplitState.MissingEndQuote, "missing closing quote"); } // add leftovers string lastItem = sb.ToString(); if (trim) { lastItem = lastItem.Trim(); } parts.Add(Intern(lastItem)); return(parts.ToArray()); }
public static void SplitJson(TextReader textReader, string tokenName, long maxItems, Func <int, TextWriter> createStream, Formatting formatting) { List <JProperty> prefixProperties = new List <JProperty>(); List <JProperty> postFixProperties = new List <JProperty>(); List <JsonWriter> writers = new List <JsonWriter>(); SplitState state = SplitState.InPrefix; long count = 0; try { using (var reader = new JsonTextReader(textReader)) { bool doRead = true; while (doRead ? reader.Read() : true) { doRead = true; if (reader.TokenType == JsonToken.Comment || reader.TokenType == JsonToken.None) { continue; } if (reader.Depth == 0) { if (reader.TokenType != JsonToken.StartObject && reader.TokenType != JsonToken.EndObject) { throw new JsonException("JSON root container is not an Object"); } } else if (reader.Depth == 1 && reader.TokenType == JsonToken.PropertyName) { if ((string)reader.Value == tokenName) { state = SplitState.InSplitProperty; } else { if (state == SplitState.InSplitProperty) { state = SplitState.InPostfix; } var property = JProperty.Load(reader); doRead = false; // JProperty.Load() will have already advanced the reader. if (state == SplitState.InPrefix) { prefixProperties.Add(property); } else { postFixProperties.Add(property); } } } else if (reader.Depth == 1 && reader.TokenType == JsonToken.StartArray && state == SplitState.InSplitProperty) { state = SplitState.InSplitArray; } else if (reader.Depth == 1 && reader.TokenType == JsonToken.EndArray && state == SplitState.InSplitArray) { state = SplitState.InSplitProperty; } else if (state == SplitState.InSplitArray && reader.Depth == 2) { if (count % maxItems == 0) { var writer = new JsonTextWriter(createStream(writers.Count)) { Formatting = formatting }; writers.Add(writer); writer.WriteStartObject(); foreach (var property in prefixProperties) { property.WriteTo(writer); } writer.WritePropertyName(tokenName); writer.WriteStartArray(); } count++; writers.Last().WriteToken(reader, true); } else { throw new JsonException("Internal error"); } } } foreach (var writer in writers) { using (writer) { writer.WriteEndArray(); foreach (var property in postFixProperties) { property.WriteTo(writer); } writer.WriteEndObject(); } } } finally { // Make sure files are closed in the event of an exception. foreach (var writer in writers) { using (writer) { } } } }
void Start() { Shadow = gameObject.FindChild("Shadow"); for (int i = 1; i <= 8; i++) { var splitGO = gameObject.FindChild("Split" + i); splitGO.renderer.enabled = false; splitGO.renderer.material.color = renderer.material.color; Splits[i - 1] = new SplitState(splitGO, Quaternion.Slerp(UnityEngine.Random.rotation, Quaternion.identity, 0.5f)); Splits[i - 1].RandomDirection = UnityEngine.Random.onUnitSphere / 2 + splitGO.transform.localPosition; } Initialized = true; }
public void StartRow() { rowCount++; _currentState = SplitState.Start; _parts.Clear(); _sb.Length = 0; _captureValue = IncludeColumn(_parts.Count); }
public void ProcessSingleChar(char ch, char separator, bool trim) { switch (_currentState) { case SplitState.Start: if (ch == '"') { _currentState = SplitState.StartQuote; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch == ' ') { _currentState = SplitState.PotentialStartSpace; } else { _currentState = SplitState.Word; } break; case SplitState.StartQuote: if (ch == '"') { _currentState = SplitState.PotentialEndQuote; } else { _currentState = SplitState.EscapedWord; } break; case SplitState.StartSeparator: if (ch == '"') { _currentState = SplitState.StartQuote; } else if (ch == separator) { break; } else if (ch == ' ') { _currentState = SplitState.PotentialStartSpace; } else { _currentState = SplitState.Word; } break; case SplitState.PotentialStartSpace: if (ch == '"') { _currentState = SplitState.StartQuote; _sb.Length = 0; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch != ' ') { _currentState = SplitState.Word; } break; case SplitState.Word: // Allow quotes in the middle of a word. // a, b "b", c if (ch == '"') { //currentState = SplitState.UnescapedQuote; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } break; case SplitState.EscapedWord: if (ch == '"') { _currentState = SplitState.PotentialEndQuote; } break; case SplitState.PotentialEndQuote: if (ch == '"') { _currentState = SplitState.EscapedWord; } else if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch == ' ') { _currentState = SplitState.PotentialEndSpace; } else { _currentState = SplitState.UnescapedQuote; } break; case SplitState.PotentialEndSpace: if (ch == separator) { _currentState = SplitState.StartSeparator; } else if (ch != ' ') { _currentState = SplitState.UnescapedQuote; } // Anything else is a case like: "abc" d // does that parse as 'abc d'? Is it an error? break; default: break; } switch (_currentState) { case SplitState.StartSeparator: { PushValue(trim); } break; case SplitState.PotentialStartSpace: case SplitState.Word: case SplitState.EscapedWord: case SplitState.PotentialEndSpace: if (_captureValue) { _sb.Append(ch); } break; case SplitState.UnescapedQuote: throw new AssertException("unescaped double quote"); case SplitState.MissingEndQuote: throw new AssertException("missing closing quote"); } }