Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Stupid Regex Parser (See related posts)

// Regex Code (lol)

  def parseForVoolish(voolishContent)
    rExps = {}
    rExps[:isVool] = /<<(.+)>>/
    rExps[:voolType] = /<<([a-zA-Z]+) (.+)\s*>>/
    rExps[:typeless] = /<< (.+)\s*>>/
    rExps[:splitQuote] = /\s*---\s*/
    rExps[:splitIRC] = /\s*<<\s*/
    parsedContent = {}

    if voolishContent =~ rExps[:isVool]
      parsedContent[:type] = 'Voolish'
      if voolishContent =~ rExps[:voolType]
        parsedContent[:type] = "#$1"
        tempContent = "#$2"
      else
        parsedContent[:type] = 'link'
        voolishContent =~ rExps[:typeless]
        tempContent = "#$1"
      end
    else
      parsedContent[:type] = 'thought'
      tempContent = voolishContent
    end
    
    if parsedContent[:type] == 'link'
      tempContent = tempContent.split(/\s*<<\s*/)
      if tempContent.length == 1
        parsedContent[:content] = tempContent[0]
      elsif tempContent.length == 2
        parsedContent[:content] = '' + tempContent[0]  + '">' + tempContent[1] +  ''
      elsif tempContent.length == 3 # Fix (link_to_remote is a function - parameters?
        parsedContent[:content] = '' + tempContent[0]  + '">' + tempContent[1] +  ' ' + tempContent[2]
      end
    end
    
    if parsedContent[:type] == 'thought'
      parsedContent[:content] = tempContent
    end
    
    if parsedContent[:type] == 'tip'
      parsedContent[:content] = tempContent
    end

    if parsedContent[:type] == 'quote'
      tempContent = tempContent.split(rExps[:splitQuote])
      parsedContent[:content] = tempContent[0] , content_tag("small", ["", tempContent[1]])
    end

    if parsedContent[:type] == 'irc'
      tempContent = tempContent.split(rExps[:splitQuote])
      ircContent = tempContent[0].gsub(rExps[:splitIRC], '
') if tempContent.length == 1 parsedContent[:content] = ircContent elsif tempContent.length == 2 parsedContent[:content] = ircContent , content_tag("small", ["", tempContent[1]]) end end return parsedContent end

You need to create an account or log in to post comments to this site.


Related Posts