home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / SQL Format252808242001.psc / CStringBuilder.cls next >
Encoding:
Visual Basic class definition  |  2001-04-25  |  3.3 KB  |  98 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CStringBuilder"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. ' *************************************************************
  15. '  Copyright ⌐2000-2001, Karl E. Peterson
  16. '  http://www.mvps.org/vb/
  17. ' *************************************************************
  18. '  Author grants royalty-free rights to use this code within
  19. '  compiled applications. Selling or otherwise distributing
  20. '  this source code is not allowed without author's express
  21. '  permission.
  22. ' *************************************************************
  23. Option Explicit
  24.  
  25. ' Win32 APIs
  26. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
  27. ' *** Use proper function, depending on VB Version!
  28. Private Declare Function VarPtrArray Lib "msvbvm50.dll" Alias "VarPtr" (Var() As Any) As Long
  29. ' Private Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (Var() As Any) As Long
  30.  
  31. ' Member variables
  32. Private m_Bump As Long
  33. Private m_Len As Long
  34. Private m_BufferLen As Long
  35. Private m_Buffer() As Byte
  36. Private m_Scratch() As Byte
  37.  
  38. ' Internal class constants
  39. Private Const defBufferBump As Long = 2048
  40. Private Const BaseModule As String = "CStringBuilder"
  41. Private Const errArgumentOutOfRange As Long = vbObjectError + 512
  42.  
  43. ' ************************************************
  44. '  Initialization and Termination
  45. ' ************************************************
  46. Private Sub Class_Initialize()
  47.    ' dotNET uses a 16-char default size, but this
  48.    ' class is really written for heavier use where
  49.    ' longer strings will be more the norm.
  50.    m_Bump = defBufferBump
  51.    m_Len = 0
  52.    ReDim m_Buffer(0 To m_Bump - 1) As Byte
  53.    ReDim m_Scratch(0 To m_Bump - 1) As Byte
  54.    m_BufferLen = UBound(m_Buffer) + 1
  55. End Sub
  56.  
  57. ' ************************************************
  58. '  Properties
  59. ' ************************************************
  60. Public Property Let BufferBump(ByVal NewVal As Long)
  61.    ' Accept new value (bytes) by which to resize buffer
  62.    ' when adjustment is needed.  Good to keep this
  63.    ' fairly large in most cases.
  64.    If NewVal > 0 Then
  65.       ' Round up, if user passed odd number.
  66.       If NewVal Mod 2 Then
  67.          NewVal = NewVal + 1
  68.       End If
  69.       ' Store number of bytes to bump buffer by.
  70.       m_Bump = NewVal
  71.    End If
  72. End Property
  73.  
  74. Public Property Get BufferBump() As Long
  75.    ' Return number of bytes buffer gets bumped by.
  76.    BufferBump = m_Bump
  77. End Property
  78.  
  79. Public Property Let Capacity(ByVal NewVal As Long)
  80.    Dim NewSize As Long
  81.    ' This is an *expensive* routine, to be avoided
  82.    ' at most reasonable costs. Adjusts the number of
  83.    ' *bytes* in string buffer.
  84.    
  85.    If NewVal > 0 Then
  86.       ' Adjust buffer to hold at least NewVal bytes,
  87.       ' adjusting to next larger bufferbump size.
  88.       NewSize = (NewVal \ m_Bump) * m_Bump
  89.       jus and Term\ m_Bumis o*seIf
  90. End Property
  91.  
  92. Public Property ump
  93.      > 0 Theokeep this
  94.    ' fairly large in most cases.
  95.    If Ncemp = m_Bcei
  96.    m_Bump = dmd_Bu2cty ump
  97.      > 0 Theokeep this
  98.  u