diff --git a/docs/formats.html b/docs/formats.html index 510c871..c08b923 100644 --- a/docs/formats.html +++ b/docs/formats.html @@ -37,6 +37,14 @@ A format converter consists of
  • Additional information required by some converters
  • +

    +An exception is the sequence %% which stands for a single +literal %. +This has been added for compatibility with the C functions +printf() and scanf(). +It behaves the same as the escaped percent \%. +

    +

    The flags *# +0- work like in the C functions printf() and scanf(). @@ -83,8 +91,6 @@ formatted (like for output) and then compared to the input. The ! flag demands that input is exactly width bytes long (normally width defines the maximum number of bytes read in many formats). -For example in "%!5d"; expects exactly 5 digits. -Fewer digits are considered loss of data and make the format fail. This feature has been added by Klemen Vodopivec, SNS.

    @@ -118,6 +124,14 @@ This feature has been added by Klemen Vodopivec, SNS. in "%=.3f"; Assure that the input is equal to the current value formatted as a float with precision 3 + + in "%!5d"; + Expect exactly 5 decimal digits. Fewer digits are considered loss of data and make the format fail. + + + in "%d%%"; + Read a decimal number followed by a % sign + diff --git a/src/StreamProtocol.cc b/src/StreamProtocol.cc index f3d1006..f77a97f 100644 --- a/src/StreamProtocol.cc +++ b/src/StreamProtocol.cc @@ -1124,6 +1124,13 @@ compileString(StreamBuffer& buffer, const char*& source, continue; } if (c == '%') { + if (buffer[formatpos+1] == '%') { + // treat %% as literal % like printf/scanf do + // replace with escaped % + buffer[formatpos] = esc; + formatpos+=2; + continue; + } debug("StreamProtocolParser::Protocol::compileString " "format=\"%s\"\n", buffer.expand(formatpos)()); nformats++;