Advertisement
runewalsh

Untitled

Nov 9th, 2019
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.32 KB | None | 0 0
  1. {$define char_consumes :=
  2.     {$ifdef complement} {$error complement} {$endif} {$ifdef rev} {$error rev} {$endif} {$ifdef return_pos} {$error return_pos} {$endif}
  3.     {$ifdef char} {$error char} {$endif} {$ifdef charset} {$error charset} {$endif}
  4.     {$ifdef char_pred} {$error char_pred} {$endif} {$ifdef codepoint_pred} {$error codepoint_pred} {$endif} {$ifdef param} {$error param} {$endif}
  5.     {$ifdef c} {$error c} {$endif} {$ifdef cs} {$error cs} {$endif} {$ifdef testCp} {$error testCp} {$endif}
  6.     {$ifdef Consume} {$error Consume} {$endif} {$ifdef ConsumeUntil} {$error ConsumeUntil} {$endif} {$ifdef ConsumeRev} {$error ConsumeRev} {$endif} {$ifdef ConsumeRevUntil} {$error ConsumeRevUntil} {$endif}
  7.     {$ifdef ConsumeAt} {$error ConsumeAt} {$endif} {$ifdef ConsumeAtUntil} {$error ConsumeAtUntil} {$endif} {$ifdef ConsumeAtRev} {$error ConsumeAtRev} {$endif} {$ifdef ConsumeAtRevUntil} {$error ConsumeAtRevUntil} {$endif}
  8.  
  9.     {$ifdef func_impl} {$error func_impl} {$endif} {$define func_impl :=
  10.         function {$ifdef implementation} {$ifdef view} StringView {$else} StringHelper {$endif} . {$endif} func
  11.         (
  12.             {$if defined(char)} {$ifndef c} c: char; {$endif}
  13.             {$elseif defined(charset)} {$ifndef cs} const cs: AnsiCharSet; {$endif}
  14.             {$elseif defined(char_pred)}
  15.                 testChar: {$ifdef param} ParametrizedCharPredicate {$else} UnparametrizedCharPredicate {$endif};
  16.                 {$ifdef param} param: pointer; {$endif}
  17.             {$elseif defined(codepoint_pred)}
  18.                 {$ifndef testCp} const testCp: {$ifdef param} ParametrizedCodepointPredicate {$else} UnparametrizedCodepointPredicate {$endif}; {$endif}
  19.                 {$ifdef param} param: pointer; {$endif}
  20.             {$else} {$error need char/charset/char_pred/codepoint_pred} {$endif}
  21.             {$ifndef return_pos} var {$endif} p: {$ifdef view} SizeUint {$else} SizeInt {$endif}
  22.         ): {$ifdef return_pos} {$ifdef view} SizeUint {$else} SizeInt {$endif} {$else} boolean {$endif};
  23.     {$ifdef implementation}
  24.         {$ifndef return_pos} var startp: {$ifdef view} SizeUint {$else} SizeInt {$endif}; {$endif}
  25.         {$ifdef codepoint_pred} var goodp: {$ifdef view} SizeUint {$else} SizeInt {$endif}; {$endif}
  26.         begin
  27.         {$ifndef return_pos} startp := p; {$endif}
  28.         {$ifdef codepoint_pred} goodp := p; {$endif}
  29.  
  30.         {$ifdef unroll} {$error unroll} {$endif} {$define unroll :=
  31.             while
  32.                 {$ifdef rev}
  33.                     {$ifdef view} (p >= unrolls) {$else} (p > unrolls) {$endif}
  34.                 {$else}
  35.                     {$ifdef view} (p + (unrolls - 1) < n) {$else} (p + (unrolls - 1) <= length(self)) {$endif}
  36.                 {$endif}
  37.                 {$define rep :=
  38.                     and {$ifdef complement} not {$endif}
  39.                 {$if defined(char) or defined(charset)}
  40.                     (self {$ifdef view} .p {$endif}[p {$ifdef rev} - 1 - repid {$else} + repid {$endif}] {$ifdef char} = c {$else} in cs {$endif} )
  41.                 {$elseif defined(char_pred)}
  42.                     testChar(self {$ifdef view} .p {$endif}[p {$ifdef rev} - 1 - repid {$else} + repid {$endif}] {$ifdef param}, param {$endif} )
  43.                 {$elseif defined(codepoint_pred)}
  44.                     {$if repid > 0} {$error no unrolls for codepoint_pred} {$endif}
  45.                     testCp( {$ifdef rev} PrevCp(p) {$else} NextCp(p) {$endif} {$ifdef param}, param {$endif} )
  46.                 {$else}
  47.                     {$error need char/charset/char_pred/codepoint_pred}
  48.                 {$endif}} {$define times := unrolls} {$include repeat.inc}
  49.             do
  50.             {$if defined(char) or defined(charset) or defined(char_pred)}
  51.                 {$ifdef rev} dec {$else} inc {$endif} (p, unrolls)
  52.             {$elseif defined(codepoint_pred)}
  53.                 {$if unrolls > 1} {$error no unrolls for codepoint_pred} {$endif}
  54.                 goodp := p
  55.             {$else} {$error need char/charset/char_pred/codepoint_pred} {$endif};
  56.  
  57.             {$if defined(codepoint_pred)} p := goodp; {$endif}}
  58.  
  59.             {$ifdef unrolls} {$error unrolls} {$endif}
  60.             {$if defined(char) or defined(charset) or defined(char_pred)}
  61.                 {$define unrolls := 4} unroll
  62.             {$endif}
  63.             {$define unrolls := 1} unroll
  64.             {$undef unrolls}
  65.             {$undef unroll}
  66.  
  67.             result := {$ifdef return_pos} p {$else} p <> startp {$endif};
  68.         end;
  69.     {$endif}}
  70.  
  71.     {$ifdef versions_for_condition} {$error versions_for_condition} {$endif} {$define versions_for_condition :=
  72.         {$ifdef func} {$error func} {$endif}
  73.         {$define func := Consume} func_impl {$define func := ConsumeAt} {$define return_pos} func_impl {$undef return_pos}
  74.         {$define func := ConsumeUntil} {$define complement} func_impl {$define func := ConsumeAtUntil} {$define return_pos} func_impl {$undef return_pos} {$undef complement}
  75.         {$define func := ConsumeRev} {$define rev} func_impl {$define func := ConsumeAtRev} {$define return_pos} func_impl {$undef return_pos} {$undef rev}
  76.         {$define func := ConsumeRevUntil} {$define rev} {$define complement} func_impl {$define func := ConsumeAtRevUntil} {$define return_pos} func_impl {$undef return_pos} {$undef rev} {$undef complement}
  77.         {$undef func}
  78.         {$undef Consume} {$undef ConsumeUntil} {$undef ConsumeRev} {$undef ConsumeRevUntil}
  79.         {$undef ConsumeAt} {$undef ConsumeAtUntil} {$undef ConsumeAtRev} {$undef ConsumeAtRevUntil}}
  80.  
  81.     {$define char} versions_for_condition {$undef char}
  82.     {$define charset} versions_for_condition {$undef charset}
  83.     {$define char_pred} versions_for_condition {$define param} versions_for_condition {$undef param} {$undef char_pred}
  84.     {$define codepoint_pred} versions_for_condition {$define param} versions_for_condition {$undef param} {$undef codepoint_pred}
  85.  
  86.     {$define charset} {$define cs := string.AsciiWhitespace}
  87.         {$define Consume := ConsumeWhitespaceA} {$define ConsumeRev := ConsumeWhitespaceARev} {$define ConsumeUntil := ConsumeUntilWhitespaceA} {$define ConsumeRevUntil := ConsumeUntilWhitespaceARev}
  88.         {$define ConsumeAt := ConsumeWhitespaceAAt} {$define ConsumeAtRev := ConsumeWhitespaceAAtRev} {$define ConsumeAtUntil := ConsumeUntilWhitespaceAAt} {$define ConsumeAtRevUntil := ConsumeUntilWhitespaceAAtRev}
  89.         versions_for_condition
  90.     {$undef cs} {$undef charset}
  91.  
  92.     {$define codepoint_pred} {$define testCp := Codepoint.TestWhitespace}
  93.         {$define Consume := ConsumeWhitespaceCp} {$define ConsumeRev := ConsumeWhitespaceCpRev} {$define ConsumeUntil := ConsumeUntilWhitespaceCp} {$define ConsumeRevUntil := ConsumeUntilWhitespaceCpRev}
  94.         {$define ConsumeAt := ConsumeWhitespaceCpAt} {$define ConsumeAtRev := ConsumeWhitespaceCpAtRev} {$define ConsumeAtUntil := ConsumeUntilWhitespaceCpAt} {$define ConsumeAtRevUntil := ConsumeUntilWhitespaceCpAtRev}
  95.         versions_for_condition
  96.     {$undef testCp} {$undef codepoint_pred}
  97.  
  98.     {$undef versions_for_condition} {$undef func_impl}
  99.  
  100.     {$undef view}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement