public void Pretty() { List <SGFToken> lNewList = new List <SGFToken>(Tokens.Count); SGFToken lSGFNewLineToken = new SGFToken(Environment.NewLine); int lParamCnt = 0; int lLineLen = 0; foreach (SGFToken lSGFToken in Tokens) { if (lSGFToken.Type == TokenType.OPENPARAN) { lParamCnt++; lNewList.Add(lSGFToken); lLineLen = lLineLen + lSGFToken.ToString().Length; } else if (lSGFToken.Type == TokenType.CLOSEPARAN) { lParamCnt--; lNewList.Add(lSGFToken); lNewList.Add(lSGFNewLineToken); lLineLen = 0; } else if (lSGFToken.Type == TokenType.SEMICOMMA) { lNewList.Add(lSGFToken); } else if (lSGFToken.Type == TokenType.PROPERTY) { bool lNewLine = false; SGFPropertyInfo lSGFPropertyInfo = SGFInfo.GetSGFPropertyInfo(lSGFToken.Property.Name); if (lSGFPropertyInfo == null) { lNewLine = true; } else if ((lSGFPropertyInfo.PropertyType == SGFPropertyType.GameInfo) || (lSGFPropertyInfo.PropertyType == SGFPropertyType.None)) { lNewLine = true; } if (lLineLen + lSGFToken.ToString().Length > 65) { lNewLine = true; } if (lNewLine) { lNewList.Add(lSGFNewLineToken); lLineLen = 0; } lNewList.Add(lSGFToken); lLineLen = lLineLen + lSGFToken.ToString().Length; } } Tokens = lNewList; }
protected SGFPropertyInfo FindSGFPropertyInfo(string id) { SGFPropertyInfo lSGFPropertyInfo = null; if (!Dictionary.TryGetValue(id, out lSGFPropertyInfo)) { return(null); } return(lSGFPropertyInfo); }
public void ProcessProperty(Property property) { property.Name = property.Name.Trim(); property.Value = property.Value.Trim(); if (property.Name == "SZ") { Int32.TryParse(property.Value, out BoardSize); } else { if (!ConvertToSGFCoords && !ConvertToGoCoords) { return; } SGFPropertyInfo lSGFPropertyInfo = SGFInfo.GetSGFPropertyInfo(property.Name); if (lSGFPropertyInfo == null) { return; } if ((lSGFPropertyInfo.PropertyValueType != SGFPropertyValueType.Stone) && (lSGFPropertyInfo.PropertyValueType != SGFPropertyValueType.Point) && (lSGFPropertyInfo.PropertyValueType != SGFPropertyValueType.Move)) { return; } string lValue = property.Value; string lValue1 = lValue; string lValue2 = string.Empty; int lPos = lValue.IndexOf(':'); if (lPos > 0) { lValue1 = lValue.Substring(0, lPos - 1); lValue2 = lValue.Substring(lPos + 1); } else if (lPos == 0) { lValue1 = string.Empty; lValue2 = lValue1.Substring(1); } Coords lCoord = new Coords(lValue1, BoardSize); if (ConvertToSGFCoords) { property.Value = lCoord.ToSGFCoords(BoardSize); } else if (ConvertToGoCoords) { property.Value = lCoord.ToGoCoords(); } if (lValue2 != string.Empty) { property.Value = property.Value + ":" + lValue2; } if (lSGFPropertyInfo.List) { for (int i = 0; i < property.AdditionalValues.Count; i++) { string lAddtValue = property.AdditionalValues[i]; lCoord = new Coords(lAddtValue, BoardSize); if (ConvertToSGFCoords) { lAddtValue = lCoord.ToSGFCoords(BoardSize); } else if (ConvertToGoCoords) { lAddtValue = lCoord.ToGoCoords(); } property.AdditionalValues[i] = lAddtValue; } } } }