Guest User

Untitled

a guest
Aug 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 3.89 KB | None | 0 0
  1.  
  2. function HH_TRIMM(content)
  3.     let content = a:content
  4.     while stridx(content, " ") == 0 || stridx(content, "\t") == 0
  5.         let content = strpart(content, 1)
  6.     endwhile
  7.     while strpart(content, strlen(content) - 1) == " "
  8.         let content = strpart(content, 0, strlen(content) -1)
  9.     endwhile
  10.     return content
  11. endfunction
  12.  
  13. function HH_GET_CLASS_NAME()
  14.     0
  15.     let NumLineClass = search("class ")
  16.     if NumLineClass == 0
  17.         echo "ERROR : Missing class"
  18.         return
  19.     endif
  20.     let classLine = HH_TRIMM(getline(NumLineClass))
  21.     let classLine = HH_TRIMM(strpart(classLine, 5))
  22.     if stridx(classLine, "{") != -1
  23.         let classLine = strpart(classLine, 0, stridx(classLine, "{"))
  24.     endif
  25.     if stridx(classLine, ":") != -1
  26.         let classLine = strpart(classLine, 0, stridx(classLine, ":"))
  27.     endif
  28.     return HH_TRIMM(classLine)
  29. endfunction
  30.  
  31. function HH_GET_END_CLASS(startClass)
  32.     let result = a:startClass
  33.     let tmp = result + 1
  34.     while tmp > result
  35.         let result = tmp
  36.         let tmp = search("}")
  37.     endwhile
  38.     return result - 1
  39. endfunction
  40.  
  41. function HH_GET_START_NAME(content)
  42.     let endword = stridx(a:content, "(")
  43.     let startword = endword - 1
  44.     let tmp = -1
  45.     while tmp == -1 && startword != 0
  46.         let startword = startword - 1
  47.         let test = strpart(a:content, startword, endword - startword)
  48.         let tmp = stridx(test, " ")
  49.     endwhile
  50.     return startword + 1
  51. endfunction
  52.  
  53. function HH_IS_EQ(content)
  54.     if stridx(a:content, "=") == -1
  55.         return 0
  56.     else
  57.         return 1
  58.     endif
  59. endfunction
  60.  
  61. function HH_CLEAN_EQ_2(content)
  62.     let content = a:content
  63.     let eq = stridx(content, '=')
  64.     let tmp = strpart(content, eq)
  65.     let endeq = stridx(tmp, ',')
  66.     if endeq == -1
  67.         let endeq = stridx(tmp, ')')
  68.     endif
  69.     if endeq == -1
  70.         return content
  71.     endif
  72.     let endeq = endeq + eq
  73.     let part1 = HH_TRIMM(strpart(content, 0, eq))
  74.     let part2 = HH_TRIMM(strpart(content, endeq))
  75.     return part1 . part2
  76. endfunction
  77.  
  78. function HH_CLEAN_EQ(content)
  79.     let content = a:content
  80.     while HH_IS_EQ(content) == 1
  81.         let content = HH_CLEAN_EQ_2(content)
  82.     endwhile
  83.     return content
  84. endfunction
  85.  
  86. function HH_IS_OK(content)
  87.     let content = a:content
  88.     if strpart(content, strlen(content) - 1) != ";"
  89.         return 0
  90.     endif
  91.     if strpart(HH_TRIMM(content), 0, 1) == '*'
  92.         return 0
  93.     endif
  94.     if strpart(HH_TRIMM(content), 0, 1) == '/'
  95.         return 0
  96.     endif
  97.     if strpart(HH_TRIMM(content), 0, 1) == '#'
  98.         return 0
  99.     endif
  100.     if stridx(content, "(") == -1
  101.         return 0
  102.     endif
  103.     if stridx(content, ' = 0;') != -1
  104.         return 0
  105.     endif
  106.     return 1
  107. endfunction
  108.  
  109. function HH_CONVERT()
  110.     let className = HH_GET_CLASS_NAME()
  111.     let startClass = search("{") + 1
  112.     let endClass = HH_GET_END_CLASS(startClass)
  113.     let result = '# include "'. expand("%") . '"' . "\n"
  114.     for line in range(startClass, endClass)
  115.         let content = getline(line)
  116.         if HH_IS_OK(content) == 1
  117.             let startName = HH_GET_START_NAME(content)
  118.             let part1 = strpart(content, 0, startName)
  119.             let part2 = strpart(content, startName)
  120.             let content = part1 . ' ' . className . '::' . part2
  121.             let content = substitute(content, 'virtual', '', '')
  122.             let content = substitute(content, 'static', '', '')
  123.             let content = HH_CLEAN_EQ(content)
  124.             let content = strpart(content, 0, strlen(content) - 1)
  125.             let content = HH_TRIMM(content)
  126.             let result = result . "\n" . content . "\n"
  127.             let result = result . "{\n"
  128.             let result = result . "}\n"
  129.         endif
  130.     endfor
  131.     let fileName = expand("%:p:r") . '.cpp'
  132.     exe "edit " . fileName
  133.     put = result
  134.     5
  135. endfunction
  136.  
  137. command! HH call HH_CONVERT()
Add Comment
Please, Sign In to add comment