The Squirrel interpreter. See http://www.squirrel-lang.org/
squirrel/sqstring.h@3:7268a3ceaffc, 2014-12-16 (annotated)
- Committer:
- jhnwkmn
- Date:
- Tue Dec 16 11:39:42 2014 +0000
- Revision:
- 3:7268a3ceaffc
- Parent:
- 0:97a4f8cc534c
Accepts \r as line terminator as well.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhnwkmn | 0:97a4f8cc534c | 1 | /* see copyright notice in squirrel.h */ |
jhnwkmn | 0:97a4f8cc534c | 2 | #ifndef _SQSTRING_H_ |
jhnwkmn | 0:97a4f8cc534c | 3 | #define _SQSTRING_H_ |
jhnwkmn | 0:97a4f8cc534c | 4 | |
jhnwkmn | 0:97a4f8cc534c | 5 | inline SQHash _hashstr (const SQChar *s, size_t l) |
jhnwkmn | 0:97a4f8cc534c | 6 | { |
jhnwkmn | 0:97a4f8cc534c | 7 | SQHash h = (SQHash)l; /* seed */ |
jhnwkmn | 0:97a4f8cc534c | 8 | size_t step = (l>>5)|1; /* if string is too long, don't hash all its chars */ |
jhnwkmn | 0:97a4f8cc534c | 9 | for (; l>=step; l-=step) |
jhnwkmn | 0:97a4f8cc534c | 10 | h = h ^ ((h<<5)+(h>>2)+(unsigned short)*(s++)); |
jhnwkmn | 0:97a4f8cc534c | 11 | return h; |
jhnwkmn | 0:97a4f8cc534c | 12 | } |
jhnwkmn | 0:97a4f8cc534c | 13 | |
jhnwkmn | 0:97a4f8cc534c | 14 | struct SQString : public SQRefCounted |
jhnwkmn | 0:97a4f8cc534c | 15 | { |
jhnwkmn | 0:97a4f8cc534c | 16 | SQString(){} |
jhnwkmn | 0:97a4f8cc534c | 17 | ~SQString(){} |
jhnwkmn | 0:97a4f8cc534c | 18 | public: |
jhnwkmn | 0:97a4f8cc534c | 19 | static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 ); |
jhnwkmn | 0:97a4f8cc534c | 20 | SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval); |
jhnwkmn | 0:97a4f8cc534c | 21 | void Release(); |
jhnwkmn | 0:97a4f8cc534c | 22 | SQSharedState *_sharedstate; |
jhnwkmn | 0:97a4f8cc534c | 23 | SQString *_next; //chain for the string table |
jhnwkmn | 0:97a4f8cc534c | 24 | SQInteger _len; |
jhnwkmn | 0:97a4f8cc534c | 25 | SQHash _hash; |
jhnwkmn | 0:97a4f8cc534c | 26 | SQChar _val[1]; |
jhnwkmn | 0:97a4f8cc534c | 27 | }; |
jhnwkmn | 0:97a4f8cc534c | 28 | |
jhnwkmn | 0:97a4f8cc534c | 29 | |
jhnwkmn | 0:97a4f8cc534c | 30 | |
jhnwkmn | 0:97a4f8cc534c | 31 | #endif //_SQSTRING_H_ |