private void AppendPOString(string value) { if (value == null) { value = string.Empty; } var startIndex = _builder.Length; _builder.Append('"'); POString.Encode(_builder, value, 0, value.Length); _builder.Append('"'); var endIndex = _builder.Length; if (!(!HasFlags(Flags.IgnoreLongLines) && endIndex - _lineStartIndex > MaxLineLength || !HasFlags(Flags.IgnoreLineBreaks) && IndexOfNewLine(startIndex + 1, endIndex - 1) >= 0)) { return; } startIndex++; _builder.Insert(startIndex, _stringBreak); _lineStartIndex = startIndex + _stringBreak.Length; _lineStartIndex--; while ((startIndex = GetStringBreakIndex()) >= 0) { _builder.Insert(startIndex, _stringBreak); _lineStartIndex = startIndex + _stringBreak.Length; _lineStartIndex--; } }
void BuildString(string value) { var startIndex = _builder.Length; _builder.Append('"'); POString.Encode(_builder, value, 0, value.Length); _builder.Append('"'); var endIndex = _builder.Length; if (!(!_flags.HasFlag(Flags.IgnoreLongLines) && endIndex - _lineStartIndex > maxLineLength || (!_flags.HasFlag(Flags.IgnoreLineBreaks) && IndexOfNewLine(startIndex + 1, endIndex - 1) >= 0))) { return; } startIndex++; _builder.Insert(startIndex, stringBreak); _lineStartIndex = startIndex + stringBreak.Length; _lineStartIndex--; while ((startIndex = GetStringBreakIndex()) >= 0) { _builder.Insert(startIndex, stringBreak); _lineStartIndex = startIndex + stringBreak.Length; _lineStartIndex--; } }
private bool TryReadStringPart(StringBuilder builder) { var lineLength = _line.Length; if (_columnIndex >= lineLength || _line[_columnIndex] != '"') { AddError(DiagnosticCodes.ExpectedToken, new TextLocation(_lineIndex, _columnIndex >= 0 ? _columnIndex : lineLength), '"'); return(false); } var startIndex = ++_columnIndex; for (; _columnIndex < lineLength; _columnIndex++) { if (_line[_columnIndex] == '"' && !IsEscaped(startIndex)) { var endIndex = _columnIndex++; _columnIndex = FindNextTokenInLine(); if (_columnIndex >= 0) { AddError(DiagnosticCodes.UnexpectedToken, new TextLocation(_lineIndex, lineLength)); return(false); } var index = POString.Decode(builder, _line, startIndex, endIndex - startIndex); if (index >= 0) { AddError(DiagnosticCodes.InvalidEscapeSequence, new TextLocation(_lineIndex, index)); return(false); } _columnIndex = lineLength; return(true); } } AddError(DiagnosticCodes.ExpectedToken, new TextLocation(_lineIndex, lineLength), '"'); return(false); bool IsEscaped(int si) { bool result = false; for (var i = _columnIndex - 1; i >= si; i--) { if (_line[i] == '\\') { result = !result; } else { break; } } return(result); } }
public override string ToString() { var idKindToken = POKey.GetIdKindToken(IdKind) ?? "?"; var value = Value ?? string.Empty; var sb = new StringBuilder(); sb.Append(idKindToken); sb.Append(' '); sb.Append('"'); POString.Encode(sb, value, 0, value.Length); sb.Append('"'); return(sb.ToString()); }
public POParser(POParserSettings settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (settings.ReadContentTypeHeaderOnly) { _flags |= Flags.ReadContentTypeHeaderOnly; } if (settings.ReadHeaderOnly) { _flags |= Flags.ReadHeaderOnly; } #if USE_COMMON if (settings.PreserveHeadersOrder) { _flags |= Flags.PreserveHeadersOrder; } #endif if (settings.SkipInfoHeaders) { _flags |= Flags.SkipInfoHeaders; } if (settings.SkipComments) { _flags |= Flags.SkipComments; } else { _commentBuffer = new List <KeyValuePair <TextLocation, string> >(); } _keyStringNewLine = POString.NewLine(settings.StringDecodingOptions?.KeepKeyStringsPlatformIndependent ?? false); _translationStringNewLine = POString.NewLine(settings.StringDecodingOptions?.KeepTranslationStringsPlatformIndependent ?? false); _builder = new StringBuilder(); }
public static bool TryParse(string value, out POPreviousValueComment result) { if (value == null) { throw new ArgumentNullException(nameof(value)); } string idKindToken = null; value = value.Trim(); var index = value.FindIndex(char.IsWhiteSpace); if (index >= 0) { idKindToken = value.Remove(index); value = value.Substring(index + 1).TrimStart(); } int length; POIdKind idKind; StringBuilder sb; if (index < 0 || (length = value.Length) < 2 || value[0] != '"' || value[length - 1] != '"' || (idKind = POKey.GetIdKind(idKindToken)) == POIdKind.Unknown || POString.Decode(sb = new StringBuilder(), value, 1, length - 2) >= 0) { result = null; return(false); } result = new POPreviousValueComment { IdKind = idKind, Value = sb.ToString() }; return(true); }
public static bool TryParse(string value, POStringDecodingOptions options, out POPreviousValueComment result) { return(TryParse(value, POString.NewLine(options?.KeepKeyStringsPlatformIndependent ?? false), out result)); }