snippet for debugging constants

Share your advanced PureBasic knowledge/code with the community.
#NULL
Addict
Addict
Posts: 1499
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

snippet for debugging constants

Post by #NULL »

this code grabs your clipboard text, searches it for constants
and generates a new clipboard text, a PB-code to debug these constants.

Code: Select all

; conDeb.pb
; (constant debugger)
; searches clipboard text for constants
; and sets a PureBasic Debug code for these
; constants as new clipboard text.

; http://www.purebasic.fr/german/viewtopic.php?t=14517
; by '#null' (thanks to 'sibru')



text.s = GetClipboardText()

NewList const.s()
AddElement(const())

For i=1 To Len(text)
  char = Asc( Mid(text,i,1) )
  If char = 35;"#"
    switch = 1
    const()+"#"
  ElseIf switch And Not FindString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_", Chr(char), 1)
    switch = 0
    AddElement(const())
  ElseIf switch
    const()+Chr(char)
  EndIf
Next

text=""
ForEach const()
  If const()
    text + ";" + const() + #CRLF$
  EndIf
Next
text + #CRLF$
ForEach const()
  If const()
    text + "Debug " + Chr(34) + const() + " = " + Chr(34) + " + Str(" + const() + ")" + #CRLF$
  EndIf
Next

SetClipboardText(text)

PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: snippet for debugging constants

Post by PB »

Useful, thanks! :)
Post Reply