- Inherits from:
- Object
- Conforms to:
- DComparable, DDataReadable, DDataWritable, DDatable, DSizeable, DTextScannable, DTextable
- Declared in:
- DData.h
Object
|
+---DData
Class Description
The DData class implements a number of methods for manipulating data strings.
- Last modified:
- 31-Oct-2007 (DData.h)
Instance Variables
- private unsigned long _size
- the allocated size for the data
- private unsigned _extra
- the extra size amount
- private unsigned long _length
- the length of the data
- private unsigned char *_data
- the data
- private unsigned long _pntr
- the 'file pointer' for the protocols
- private int _error
- the last reported error (or 0)
- Constructors
- - (DData *) init
- Initialise to an empty data string
- Returns:
- the object
- - (DData *) init :(const unsigned char *) data :(unsigned long) length
- Initialise the instance with data
- Parameters:
- data - the data
length - the length of the data
- Returns:
- the string object
- Copy related methods
- - shallowCopy
- Do a shallow copy of the data string object
- Returns:
- the object
- Deconstructor
- - free
- Free the object
- Returns:
- the object
- Size methods
- - (DData *) extra :(unsigned) extra
- Set the amount of extra size increase if the size must be extended
- Parameters:
- extra - the amount (def. 0)
- Returns:
- the object
- - (DData *) size :(unsigned long) size
- Insure the size for the data string
- Parameters:
- size - the requested size for the data
- Returns:
- the object
- Conversion methods
- - (unsigned long) hash
- Calculate the hash of the data string
- Returns:
- the hash value
- - (DText *) toBase64
- Convert to Base64
- Returns:
- a (new) text string object (or nil)
- - (DText *) toPrintable
- Convert to a text string with printable characters
(by changing non-printable characters to a dot character)
- Returns:
- a (new) text string object
- - (DText *) tohexString
- Convert the data string to a hexidecimal text string (every
character in the string is converted to two text characters
hexadecimal)
- Returns:
- the (new) string object
- DTextable protocol methods
- - (DText *) toText
- Convert the object to a text string without any
conversion. (see toPrintable for a method that
convert the data object to a true printable text object)
- Returns:
- a (new) text string object
- Data string setters
- - (DData *) clear
- Clear the data string
- Returns:
- the object
- - (DData *) fromBase64 :(const char *) cstring
- Set the data string with Base64 converted data
- Parameters:
- cstring - the c-string with the base 64 codes
- Returns:
- the object
- - (DData *) set :(const unsigned char *) data :(unsigned long) length
- Set data in the data string
- Parameters:
- data - the data for the string ('\0' allowed)
length - the length of the data
- Returns:
- the object
- - (DData *) set :(const unsigned char *) data :(long) from :(long) to
- Set a substring of data in the data string
- Parameters:
- data - the data for the string ('\0' allowed)
from - the start in the data
to - the end in the data (incl)
- Returns:
- the object
- Byte methods
- - (DData *) delete :(long) index
- Delete the byte at the given index
- Parameters:
- index - the index
- Returns:
- the object
- - (unsigned char) get :(long) index
- Get the byte at the given index
- Parameters:
- index - the index
- Returns:
- the byte from the data string
- - (DData *) put :(long) index :(unsigned char) byte
- Put a byte at the given index
- Parameters:
- index - the index (-length..+length)
byte - the byte to be placed
- Returns:
- the object
- Slice methods
- - (DData *) delete :(long) from :(long) to
- Delete a substring
- Parameters:
- from - the start index
to - the end index (to >= from)
- Returns:
- the object
- - (DData *) get :(long) from :(long) to
- Return a substring
- Parameters:
- from - the start index
to - the end index (to >= from)
- Returns:
- a (new) data string object
- - (DData *) insert :(long) from :(long) to :(const unsigned char *) data :(unsigned long) length
- Insert a data string in a part of the data string
- Parameters:
- from - the start index
to - the end index (to >= (from-1))
data - the new data
length - the length of the new data
- Returns:
- the object
- Data string member methods
- - (const unsigned char *) data
- Return the pointer to the data of the string
- Returns:
- the pointer to the data
- - (int) error
- Return the last error
- Returns:
- the error (0, ENODATA)
- - (BOOL) isEmpty
- Check if the data string is empty
- Returns:
- Is it empty ?
- - (unsigned long) length
- Return the length of the data string
- Returns:
- the length
- - (unsigned long) size
- Return the size of the data string in bytes
- Returns:
- the size
- DDatable protocol methods
- - (DData *) toData
- Convert the object to a data string object
- Returns:
- a (new) data string object
- DDataReadable protocol methods
- - (BOOL) isEof
- Is the end of the readable reached ?
- Returns:
- is it?
- - (unsigned char) readByte
- Read a byte
- Returns:
- the byte read (or 0)
- - (char) readChar
- Read a character
- Returns:
- the character read (or EOS)
- - (DData *) readData :(unsigned long) length
- Read a data string
- Parameters:
- length - the length of the data
- Returns:
- a (new) data object (empty if no data available)
- - (unsigned long) readData :(unsigned char *) dest :(unsigned long) length
- Read a data string
- Parameters:
- dest - the destination buffer
length - the length of the data (and minimum size of dest)
- Returns:
- the actual number of bytes read
- - (double) readDouble
- Read a double
- Returns:
- the double read (or 0.0)
- - (long) readLong
- Read a long
- Returns:
- the long read (or 0)
- - (short) readShort
- Read a short
- Returns:
- the short read (or 0)
- - (DText *) readText :(unsigned long) length
- Read text string (not-print characters are replaced by a '.')
- Parameters:
- length - the length of the text to be read
- Returns:
- a (new) text string object
- TextScannable protocol methods
- - (BOOL) cmatch :(const char *) cstring
- Match a string case sensitive; if the string matched, the current position in
the readable is moved to the location after the matched string.
- Parameters:
- cstring - the c-string to be matched
- Returns:
- does the string match ?
- - (BOOL) imatch :(const char *) cstring
- Match a string case insensitive; if the string matched, the current position in
the readable is moved to the location after the matched string.
- Parameters:
- cstring - the c-string to be matched
- Returns:
- does the string match ?
- - (int) scanInt :(int) wrong
- Scan for a (decimal) integer value
- Parameters:
- wrong - the value returned if there is no int to scan
- Returns:
- the integer read (or the wrong value)
- - (DText *) scanText :(char) separator
- Scan for a text string until a separator character. The separator character is
is not part of the returned string and is skipped in the Readable.
- Returns:
- a (new) text string (or nil if the separator is not found)
- - (DText *) scanText :(const char *) separators :(char *) separator
- Scan for a text string until one of the separator characters in the
separator string. The matched separator character is is not part of
the returned string, is skipped in the text object and is returned in
the separator argument.
- Parameters:
- separators - the c-string with the separators
separator - the destination for the actual matched separator character (or NULL)
- Returns:
- a (new) text string (or nil if none of the separators is found)
- - (int) skipChar :(char) ch
- Skip characters
- Parameters:
- ch - the character to be skipped
- Returns:
- the number of characters skipped
- - (int) skipWhiteSpace
- Skip whitespace
- Returns:
- the number of characters skipped
- DDataWritable protocol methods
- - (BOOL) flush
- Flush the output buffers
- Returns:
- success
- - (BOOL) writeByte :(unsigned char) byte
- Write the byte
- Parameters:
- byte - the byte to be written
- Returns:
- success
- - (BOOL) writeChar :(char) ch
- Write the character
- Parameters:
- ch - the character to be written
- Returns:
- success
- - (BOOL) writeData :(const unsigned char *) text :(unsigned long) length
- Write the data string
- Parameters:
- data - the data to be written
length - the length of the data
- Returns:
- success
- - (BOOL) writeDouble :(double) val
- Write the double
- Parameters:
- val - the double to be written
- Returns:
- the object
- - (BOOL) writeLong :(long) val
- Write the long
- Parameters:
- val - the long to be written
- Returns:
- success
- - (BOOL) writeShort :(short) sh
- Write the short
- Parameters:
- sh - the short to be written
- Returns:
- success
- - (BOOL) writeText :(const char *) text
- Write text string
- Parameters:
- text - the text to be written
- Returns:
- success
- DDataReadable and DDataWritable protocol methods
- - (BOOL) seek :(unsigned long) offset :(int) origin
- Move the current position to a location
- Parameters:
- offset - the offset from the origin (in bytes)
origin - the origin for the offset (0=begin, 1=current, 2=end,others = no change)
- Returns:
- the object
- - (BOOL) skip :(unsigned long) offset
- Skip a number of positions
- Parameters:
- offset - the number of bytes to skip
- Returns:
- success
- - (unsigned long) tell
- Tell the current position in the writeable
- Returns:
- the current position
- Data string manipulation methods
- - (DData *) append :(const unsigned char *) data :(unsigned long) length
- Append data to the data string
- Parameters:
- data - the data to be appended
length - the length of the data to be appended
- Returns:
- the object
- - (DData *) multiply :(unsigned) times
- Multiply the data string a number of times
- Parameters:
- times - the number of times the data string must be multiplied
- Returns:
- the object
- - (unsigned char) pop
- Pop one byte from the end of the data string
- Returns:
- the byte that is pulled (or 0)
- - (DData *) prepend :(const unsigned char *) data :(unsigned long) length
- Prepend data in front of the string
- Parameters:
- data - the data to be prepended
length - the length of the data to be prepended
- Returns:
- the object
- - (DData *) push :(unsigned char) ch
- Push one byte at the end of the data string
- Parameters:
- ch - the byte that is placed at the end
- Returns:
- the object
- Comparable protocol methods
- - (int) compare :(DData *) other
- Compare the data string object with another data string object
- Parameters:
- other - the object that should be compared (!= nil)
- Returns:
- the compare result (-1, 0, 1)
- Comparason methods
- - (int) bcompare :(unsigned char *) data :(unsigned long) length
- Compare the object with a data string
- Parameters:
- data - the data string
length - the length of the data string
- Returns:
- the compare result (-1, 0, 1)
- Search and replace methods
- - (unsigned long) count :(const unsigned char *) search :(unsigned long) length :(long) from :(long) to
- Count the number of occurrences of data in the data string
- Parameters:
- search - the data that should be counted
length - the length of the data to be counted
from - the start index
to - the end index (to >= from)
- Returns:
- the number of occurrences
- - (long) index :(const unsigned char *) search :(unsigned long) length :(long) from :(long) to
- Return the first index where the search data is found
- Parameters:
- search - the data that should be searched
length - the length of the data
from - the start index
to - the end index (to >= from)
- Returns:
- the first index or -1 = not found
- - (DData *) replace :(const unsigned char *) old :(unsigned long) olength :(const unsigned char *) new :(unsigned long) nlength :(long) max
- Replace in the string the occurrences of old with new, max times
- Parameters:
- old - the data that is searched
olength - the length of the searched data
new - the data that is inserted
nlength - the length of the inserted data
max - the maximum number of replaces (-1 = all)
- Returns:
- the object
- - (long) rindex :(const unsigned char *) search :(unsigned long) length :(long) from :(long) to
- Return the last index where the search data is found
- Parameters:
- search - the data that should be searched
length - the length of the data
from - the start index
to - the end index (to >= from)
- Returns:
- the last index or -1 = not found
generated 05-Nov-2007 by ObjcDoc 3.0.0