Guidance
指路人
g.yi.org
software / rapidq / Examples / String & Text / qhash.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' QHash Component
' ------------------------------------------------------
' by Daitau Aaron (daitau@hotmail.com)
'
' This tries to imitate perl hash using QStringList
' Currently you may only assign simple strings as values

     $TYPECHECK ON

     TYPE QHash EXTENDS QOBJECT

      keys AS QSTRINGLIST
      values AS QSTRINGLIST
      pointer AS INTEGER

      SUB SET (k AS STRING, v AS STRING)
       WITH QHash
        DIM l AS INTEGER
        l=.keys.indexof(k)
        IF l>0 THEN
         .keys.delitems l
         .values.delitems l
        END IF
        .keys.additems k
        .values.additems v
       END WITH
      END SUB

      FUNCTION itemcount AS INTEGER
       WITH QHash
        Result=.keys.itemcount
       END WITH
      END FUNCTION

      FUNCTION GET (k AS STRING) AS STRING
       WITH QHash
        DIM l AS INTEGER
        l=.keys.indexof(k)
        IF l>=0 THEN
         Result=.values.item(l)
        ELSE
         Result=""
        END IF
       END WITH
      END FUNCTION

      FUNCTION exists (k AS STRING) AS INTEGER
       WITH QHash
        Result=(.keys.indexof(k)>=0)
       END WITH
      END FUNCTION

      SUB del (k AS STRING)
       WITH QHash
        DIM l AS INTEGER
        l=.keys.indexof(k)
        IF l>=0 THEN
         .keys.delitems l
         .values.delitems l
        END IF
       END WITH
      END SUB

      SUB clear
       WITH QHash
        .keys.clear
        .values.clear
       END WITH
      END SUB

      FUNCTION key (i AS INTEGER) AS STRING
       WITH QHash
        Result=.keys.item(i)
       END WITH
      END FUNCTION

      FUNCTION value (i AS INTEGER) AS STRING
       WITH QHash
        Result=.values.item(i)
       END WITH
      END FUNCTION

     END TYPE


' ------------------------------------------------------
' example on how to use QHash
' ------------------------------------------------------

     DIM header AS QHash

' set some keys and values
     header.SET("Host","www.yahoo.com")
     header.SET("Date","12:37:44 GMT")
     header.SET("X-cache","yes")

' print out the whole thing
     DIM i AS INTEGER
     FOR i = 0 TO header.itemcount-1
      PRINT header.key(i)+"="+header.value(i)
     NEXT i

' retrieve value by key
     PRINT
     PRINT "X-cache="+header.GET("X-cache")
' remove from hash
     PRINT "delete X-cache..."
     header.del "X-cache"
' check for existence
     IF header.exists("X-cache") THEN
      PRINT header.GET("X-cache")
     ELSE
      PRINT "X-cache does not exist"
     END IF
' clean the whole hash
     PRINT "Clean the whole hash"
     header.clear
     PRINT "Host="+header.GET("Host")
掌柜推荐
 
 
¥477.00 ·
 
 
¥918.00 ·
 
 
¥370.00 ·
 
 
¥271.00 ·
 
 
¥995.00 ·
 
 
¥1,580.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-07-13 23:57:42