Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$define char_consumes :=
- {$ifdef complement} {$error complement} {$endif} {$ifdef rev} {$error rev} {$endif} {$ifdef return_pos} {$error return_pos} {$endif}
- {$ifdef char} {$error char} {$endif} {$ifdef charset} {$error charset} {$endif}
- {$ifdef char_pred} {$error char_pred} {$endif} {$ifdef codepoint_pred} {$error codepoint_pred} {$endif} {$ifdef param} {$error param} {$endif}
- {$ifdef c} {$error c} {$endif} {$ifdef cs} {$error cs} {$endif} {$ifdef testCp} {$error testCp} {$endif}
- {$ifdef Consume} {$error Consume} {$endif} {$ifdef ConsumeUntil} {$error ConsumeUntil} {$endif} {$ifdef ConsumeRev} {$error ConsumeRev} {$endif} {$ifdef ConsumeRevUntil} {$error ConsumeRevUntil} {$endif}
- {$ifdef ConsumeAt} {$error ConsumeAt} {$endif} {$ifdef ConsumeAtUntil} {$error ConsumeAtUntil} {$endif} {$ifdef ConsumeAtRev} {$error ConsumeAtRev} {$endif} {$ifdef ConsumeAtRevUntil} {$error ConsumeAtRevUntil} {$endif}
- {$ifdef func_impl} {$error func_impl} {$endif} {$define func_impl :=
- function {$ifdef implementation} {$ifdef view} StringView {$else} StringHelper {$endif} . {$endif} func
- (
- {$if defined(char)} {$ifndef c} c: char; {$endif}
- {$elseif defined(charset)} {$ifndef cs} const cs: AnsiCharSet; {$endif}
- {$elseif defined(char_pred)}
- testChar: {$ifdef param} ParametrizedCharPredicate {$else} UnparametrizedCharPredicate {$endif};
- {$ifdef param} param: pointer; {$endif}
- {$elseif defined(codepoint_pred)}
- {$ifndef testCp} const testCp: {$ifdef param} ParametrizedCodepointPredicate {$else} UnparametrizedCodepointPredicate {$endif}; {$endif}
- {$ifdef param} param: pointer; {$endif}
- {$else} {$error need char/charset/char_pred/codepoint_pred} {$endif}
- {$ifndef return_pos} var {$endif} p: {$ifdef view} SizeUint {$else} SizeInt {$endif}
- ): {$ifdef return_pos} {$ifdef view} SizeUint {$else} SizeInt {$endif} {$else} boolean {$endif};
- {$ifdef implementation}
- {$ifndef return_pos} var startp: {$ifdef view} SizeUint {$else} SizeInt {$endif}; {$endif}
- {$ifdef codepoint_pred} var goodp: {$ifdef view} SizeUint {$else} SizeInt {$endif}; {$endif}
- begin
- {$ifndef return_pos} startp := p; {$endif}
- {$ifdef codepoint_pred} goodp := p; {$endif}
- {$ifdef unroll} {$error unroll} {$endif} {$define unroll :=
- while
- {$ifdef rev}
- {$ifdef view} (p >= unrolls) {$else} (p > unrolls) {$endif}
- {$else}
- {$ifdef view} (p + (unrolls - 1) < n) {$else} (p + (unrolls - 1) <= length(self)) {$endif}
- {$endif}
- {$define rep :=
- and {$ifdef complement} not {$endif}
- {$if defined(char) or defined(charset)}
- (self {$ifdef view} .p {$endif}[p {$ifdef rev} - 1 - repid {$else} + repid {$endif}] {$ifdef char} = c {$else} in cs {$endif} )
- {$elseif defined(char_pred)}
- testChar(self {$ifdef view} .p {$endif}[p {$ifdef rev} - 1 - repid {$else} + repid {$endif}] {$ifdef param}, param {$endif} )
- {$elseif defined(codepoint_pred)}
- {$if repid > 0} {$error no unrolls for codepoint_pred} {$endif}
- testCp( {$ifdef rev} PrevCp(p) {$else} NextCp(p) {$endif} {$ifdef param}, param {$endif} )
- {$else}
- {$error need char/charset/char_pred/codepoint_pred}
- {$endif}} {$define times := unrolls} {$include repeat.inc}
- do
- {$if defined(char) or defined(charset) or defined(char_pred)}
- {$ifdef rev} dec {$else} inc {$endif} (p, unrolls)
- {$elseif defined(codepoint_pred)}
- {$if unrolls > 1} {$error no unrolls for codepoint_pred} {$endif}
- goodp := p
- {$else} {$error need char/charset/char_pred/codepoint_pred} {$endif};
- {$if defined(codepoint_pred)} p := goodp; {$endif}}
- {$ifdef unrolls} {$error unrolls} {$endif}
- {$if defined(char) or defined(charset) or defined(char_pred)}
- {$define unrolls := 4} unroll
- {$endif}
- {$define unrolls := 1} unroll
- {$undef unrolls}
- {$undef unroll}
- result := {$ifdef return_pos} p {$else} p <> startp {$endif};
- end;
- {$endif}}
- {$ifdef versions_for_condition} {$error versions_for_condition} {$endif} {$define versions_for_condition :=
- {$ifdef func} {$error func} {$endif}
- {$define func := Consume} func_impl {$define func := ConsumeAt} {$define return_pos} func_impl {$undef return_pos}
- {$define func := ConsumeUntil} {$define complement} func_impl {$define func := ConsumeAtUntil} {$define return_pos} func_impl {$undef return_pos} {$undef complement}
- {$define func := ConsumeRev} {$define rev} func_impl {$define func := ConsumeAtRev} {$define return_pos} func_impl {$undef return_pos} {$undef rev}
- {$define func := ConsumeRevUntil} {$define rev} {$define complement} func_impl {$define func := ConsumeAtRevUntil} {$define return_pos} func_impl {$undef return_pos} {$undef rev} {$undef complement}
- {$undef func}
- {$undef Consume} {$undef ConsumeUntil} {$undef ConsumeRev} {$undef ConsumeRevUntil}
- {$undef ConsumeAt} {$undef ConsumeAtUntil} {$undef ConsumeAtRev} {$undef ConsumeAtRevUntil}}
- {$define char} versions_for_condition {$undef char}
- {$define charset} versions_for_condition {$undef charset}
- {$define char_pred} versions_for_condition {$define param} versions_for_condition {$undef param} {$undef char_pred}
- {$define codepoint_pred} versions_for_condition {$define param} versions_for_condition {$undef param} {$undef codepoint_pred}
- {$define charset} {$define cs := string.AsciiWhitespace}
- {$define Consume := ConsumeWhitespaceA} {$define ConsumeRev := ConsumeWhitespaceARev} {$define ConsumeUntil := ConsumeUntilWhitespaceA} {$define ConsumeRevUntil := ConsumeUntilWhitespaceARev}
- {$define ConsumeAt := ConsumeWhitespaceAAt} {$define ConsumeAtRev := ConsumeWhitespaceAAtRev} {$define ConsumeAtUntil := ConsumeUntilWhitespaceAAt} {$define ConsumeAtRevUntil := ConsumeUntilWhitespaceAAtRev}
- versions_for_condition
- {$undef cs} {$undef charset}
- {$define codepoint_pred} {$define testCp := Codepoint.TestWhitespace}
- {$define Consume := ConsumeWhitespaceCp} {$define ConsumeRev := ConsumeWhitespaceCpRev} {$define ConsumeUntil := ConsumeUntilWhitespaceCp} {$define ConsumeRevUntil := ConsumeUntilWhitespaceCpRev}
- {$define ConsumeAt := ConsumeWhitespaceCpAt} {$define ConsumeAtRev := ConsumeWhitespaceCpAtRev} {$define ConsumeAtUntil := ConsumeUntilWhitespaceCpAt} {$define ConsumeAtRevUntil := ConsumeUntilWhitespaceCpAtRev}
- versions_for_condition
- {$undef testCp} {$undef codepoint_pred}
- {$undef versions_for_condition} {$undef func_impl}
- {$undef view}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement