What exactly is the linear whitespace? (LWS/LWSP)

和自甴很熟 提交于 2019-12-02 20:27:09

From STD68 Augmented BNF for Syntax Specifications: ABNF

LWSP    =  *(WSP / CRLF WSP)  ; Use of this linear-white-space rule permits
                              ; lines containing only white space*
WSP     =  SP / HTAB          ; white space
CRLF    =  CR LF              ; Internet standard newline
SP      =  %x20               ; space
HTAB    =  %x09               ; horizontal tab
CR      =  %x0D               ; carriage return
LF      =  %x0A               ; linefeed

The comment on LWSP has changed in STD68 (aka RFC5234) from RFC2234 and RFC4234 and now gives advice against using this definition in new documents.

In plain English: Linear white space is: any number of spaces or horizontal tabs, and also newline (CRLF) if it is followed by at least one space or horizontal tab.

Example of strings that are linear white space:

  • [SP]
  • [HTAB]
  • [SP][SP]
  • [HTAB][HTAB]
  • [SP][HTAB][SP]
  • [SP][CR][LF][SP]
  • [CR][LF][SP][CR][LF][SP][CR][LF][HTAB]
  • [SP][CR][LF][CR][LF][SP][CR][LF][SP][CR][LF] This is TWO linear white spaces: [SP] and [SP][CR][LF][SP]. [CR][LF] is only included if it has [SP] or [HTAB] before and after.
  • [SP][VTAB][SP] Two linear white spaces: [SP] and [SP], separated by a Vertical tab.
  • [SP][CR][LF][CR][LF][CR][LF] Only the first [SP] is a linear white space. CRLF followed by CRLF is not part of specification

Thanks to Jukka K. Korpela for reminding me to check for obsoleted RFCs and to unwind for clarification that CRLF must be followed by a space or htab to be part of LWSP.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!