User talk:MichaelWodrich

From Rosetta Code
Revision as of 00:08, 29 October 2020 by rosettacode>MichaelWodrich (Created page with " [CODE] // XProfan // http://xprofan.de/start.htm // https://www.paules-pc-forum.de/forum/board/104-xprofan/ // strip_comments() Proc Min Declare int PC, i, float e, t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

[CODE] // XProfan // http://xprofan.de/start.htm // https://www.paules-pc-forum.de/forum/board/104-xprofan/

// strip_comments()

Proc Min

  Declare int PC, i, float e, t
  PC = %PCount
  e = @!(1)
  If PC > 1
    For i, 2, PC
      t = @!(i)
      e = if( (e == 0.0) and (t == 0.0), -(-e - t), if(t < e, t, e) )
    EndFor
  EndIf
  Return e

EndProc

Proc Odd

  Parameters int n
  Return TestBit(n,0)

EndProc

Proc strip_comments

  Parameters string s, delim
  Declare int posi[]
  Declare int i, min_p, p
  min_p = $7FFFFFFF
  For i, 1, Len(delim)
     posi[ i ] = InStr( mid$(delim,i,1), s )
     Case posi[ i ] > 0 : min_p = Min( posi[ i ], min_p )
  EndFor
  posi[ 0 ] = InStr( chr$(34), s )
  If (posi[0] > 0) and (posi[0] < min_p)   // if there is a string delimiter on the left side...
     If Odd( Len( Left$(s,min_p) ) - Len( translate$( Left$(s,min_p), Chr$(34), "" )) )   // ...and counting of delimiter is odd, then the sign is part of a string
        p = posi[ 0 ] + 1
        min_p = $7FFFFFFF
        Repeat
           // closing quote
           posi[ 0 ] = InStr( chr$(34), s, p )
           'Case posi[0] > 0 : posi[0] = posi[0] + p
           p = posi[ 0 ] + 1
           // find new positions after that
           For i, 1, Len(delim)
              posi[ i ] = InStr( mid$(delim,i,1), s, p )
              Case posi[ i ] > 0 : min_p = Min( posi[ i ], min_p )
           EndFor
           posi[ 0 ] = InStr( chr$(34), s, p )
           If (posi[0] > 0) and (posi[0] < min_p)   // if there is a string delimiter on the left side...
              If Odd( Len( Left$(s,min_p) ) - Len( translate$( Left$(s,min_p), Chr$(34), "" )) )   // ...and counting of delimiter is odd, then the sign is part of a string
                 p = posi[ 0 ] + 1
                 min_p = $7FFFFFFF
                 // and again....
                 CONTINUE
              EndIf
           EndIf
           BREAK
        Until min_p = 0
     EndIf
  EndIf
  Return Trim$( Left$( s, min_p - 1 ) )

EndProc

cls declare string s, t

s = " apples, pears # and bananas" t = strip_comments( s, "#;" ) Print s + "|\n-> [" + t + "]\n"

s = " apples, pears ; and bananas" t = strip_comments( s, "#;" ) Print s + "|\n-> [" + t + "]\n"

s = " apples, pears \t " t = strip_comments( s, "#;" ) Print s + "|\n-> [" + t + "]\n"

s = " " + chr$(34) + " #oh, my god " + chr$(34) + " apples, pears # and bananas" t = strip_comments( s, "#;" ) Print s + "|\n-> [" + t + "]\n"

waitkey end

/* Output:

apples, pears # and bananas|

-> [apples, pears]

apples, pears ; and bananas|

-> [apples, pears]

apples, pears 	     |

-> [apples, pears]

" #oh, my god " apples, pears # and bananas|

-> [" #oh, my god " apples, pears]

  • /

[/CODE]