Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.65 KB | None | 0 0
  1. #include <ButtonConstants.au3>
  2. #include <EditConstants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <array.au3>
  6.  
  7. $gui = GUICreate("Getter Setter", 755, 268, -1, -1)
  8. $edit1 = GUICtrlCreateEdit("", 0, 0, 345, 265)
  9. $edit2 = GUICtrlCreateEdit("", 408, 0, 345, 265)
  10. $go = GUICtrlCreateButton("Go", 355, 100, 45, 25)
  11. $copy = GUICtrlCreateButton("Copy", 355, 140, 45, 25)
  12. GUICtrlSetFont($edit1, 9, 400, 0, "Courier New")
  13. GUICtrlSetFont($edit2, 9, 400, 0, "Courier New")
  14. GUISetState(@SW_SHOW)
  15.  
  16. GUICtrlSetData($edit1, ClipGet())
  17.  
  18. Func _trim($s)
  19.     While StringLeft($s,1) == " " Or StringLeft($s,1) = "   "
  20.         $s = StringTrimLeft($s, 1)
  21.     WEnd
  22.  
  23.     While StringRight($s,1) == " " Or StringRight($s,1) = " "
  24.         $s = StringTrimRight($s, 1)
  25.     WEnd
  26.  
  27.     Return $s
  28. EndFunc
  29.  
  30. Func _StringInStrRight($s, $substring)
  31.     ;reverse
  32.     $sTemp = ""
  33.     For $i = 1 To StringLen($s)
  34.         $sTemp = StringMid($s, $i,1) & $sTemp
  35.     Next
  36.  
  37.     $i = StringInStr($sTemp, $substring)
  38.  
  39.     Return stringlen($s) - $i + 1
  40. EndFunc
  41.  
  42. Func _go()
  43.     $input = GUICtrlRead($edit1)
  44.  
  45.     Dim $aLines = StringSplit($input,@CRLF,1)
  46.     $numLines = $aLines[0]
  47.  
  48.     $outGet = "//getters" & @CRLF
  49.     $outSet = "//setters" & @CRLF
  50.  
  51.     For $i = 1 To $numLines
  52.         $line = $aLines[$i]
  53.         $line = _trim($line)
  54.  
  55.         If $line = "" Then
  56.             continueloop
  57.         EndIf
  58.  
  59.         $iSpaceFromRight = _StringInStrRight($line, " ")
  60.  
  61.         $origName = StringTrimLeft($line, $iSpaceFromRight)
  62.         $type = StringLeft($line, $iSpaceFromRight-1)
  63.  
  64.         If(StringMid($origName,1,1) = "*") Then
  65.             $origName = StringTrimLeft($origName,1)
  66.             $type = $type & "*"
  67.         EndIf
  68.         If(StringRight($origName, 1)) = ";" Then
  69.             $origName = StringTrimRight($origName, 1)
  70.         EndIf
  71.  
  72.         $name = $origName
  73.  
  74.         If(StringMid($name, 1, 1)) = "_" Then
  75.             $name = StringTrimLeft($name, 1)
  76.         EndIf
  77.  
  78.         $nameUpper = StringUpper(StringMid($name, 1, 1)) & StringTrimLeft($name, 1)
  79.  
  80.         ;MsgBox(0,0,"name: '" & $nameUpper &"'" &@CRLF & "type: '" & $type & "'")
  81.  
  82.         $outGet &= $type & " get" & $nameUpper & "() const { return " & $origName & "; }" & @CRLF
  83.         If($origName <> $name) Then
  84.             $outSet &= "void set" & $nameUpper & "(" & $type & " " & $name & ") { " & $origName & " = " & $name & "; }" & @CRLF
  85.         Else
  86.             $outSet &= "void set" & $nameUpper & "(" & $type & " " & $name & ") { this->" & $origName & " = " & $name & "; }" & @CRLF
  87.         EndIf
  88.     Next
  89.  
  90.     $outGet = StringTrimRight($outGet, 2)
  91.     $outSet = StringTrimRight($outSet, 2)
  92.  
  93.     GUICtrlSetData($edit2, $outGet & @CRLF & @CRLF & $outSet)
  94. EndFunc
  95.  
  96. While 1
  97.     $nMsg = GUIGetMsg()
  98.     Switch $nMsg
  99.         Case $GUI_EVENT_CLOSE
  100.             Exit
  101.         Case $go
  102.             _go()
  103.         Case $copy
  104.             ClipPut(GUICtrlRead($edit2))
  105.     EndSwitch
  106. WEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement