zvoulgaris

Trailing Comment Identifier drill

Feb 25th, 2021 (edited)
191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Trailing comment identifier drill (this is not a script that adds any real value, IMO, but an interesting challenge nevertheless)
  2.  
  3. function IsWithinQuotes(x::String, ind::Int64, n::Int64 = length(x))
  4.     OpenQuotes = false
  5.  
  6.     for i = 1:ind
  7.         if x[i] == '"'; OpenQuotes = !OpenQuotes; end
  8.     end
  9.  
  10.     if OpenQuotes
  11.         for i = (ind+1):n
  12.             if x[i] == '"'; return true; end
  13.         end
  14.     end
  15.  
  16.     return false
  17. end
  18.  
  19. function main(x::String) # x is a line of code
  20.     n = length(x)
  21.  
  22.     for i = 1:n
  23.         if x[i] == '#'
  24.             if !IsWithinQuotes(x, i, n); return true; end
  25.         end
  26.     end
  27.  
  28.     return false
  29. end
  30.  
RAW Paste Data