From d0ae3caca5828675335d3b19ab5dd987e7369b23 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 14 Jul 2004 16:21:44 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r1857, which included commits to RCS files with non-trunk default branches. svn path=/trunk/externals/tb/; revision=1858 --- sc4pd/headers/server/SC_Str4.h | 103 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 sc4pd/headers/server/SC_Str4.h (limited to 'sc4pd/headers/server/SC_Str4.h') diff --git a/sc4pd/headers/server/SC_Str4.h b/sc4pd/headers/server/SC_Str4.h new file mode 100644 index 0000000..306b823 --- /dev/null +++ b/sc4pd/headers/server/SC_Str4.h @@ -0,0 +1,103 @@ +/* + SuperCollider real time audio synthesis system + Copyright (c) 2002 James McCartney. All rights reserved. + http://www.audiosynth.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* a 4 byte aligned and zero padded string allows faster string operations. */ + +#ifndef _SC_Str4_ +#define _SC_Str4_ + +#include "Hash.h" +#include +#include + +#ifndef _LASTCHAR_ +#define _LASTCHAR_ +#if BYTE_ORDER == LITTLE_ENDIAN +const int32 kLASTCHAR = 0xFF000000; +#else +const int32 kLASTCHAR = 0x000000FF; +#endif +#endif + + +void str4cpy(int32 *dst, const char *src); +void mem4cpy(int32 *dst, const char *src, int charlen); + +// returns the number of pad bytes to add to a string of a given length +inline int str4padbytes(int charlen) +{ + return 4 - (charlen & 3); +} + +// converts length in bytes to length in words +inline int str4len(int charlen) +{ + return (charlen + 4) >> 2; +} + +// returns length in words of a char * +inline int str4len(const char *src) +{ + const char *src0 = src; + while (*src) { src++; } + return str4len(src - src0); +} + +// returns length in words of a int32 * +inline int str4len(const int32 *src) +{ + const int32 *src0 = src; + while (*src++ & kLASTCHAR) {} + int wordlen = src - src0; + return wordlen; +} + +// returns length in words of a int32 * +inline bool str4eq(const int32 *a, const int32 *b) +{ + while(true) { + if (*a != *b) return false; + if ((*a & kLASTCHAR) == 0) return true; + a++; b++; + } +} + +// copy an int32 * +inline void str4cpy(int32 *dst, const int32 *src) +{ + int32 c; + do { + *dst++ = c = *src++; + } while (c & kLASTCHAR); +} + +inline int sc_atoi(char *string) +{ + int value = 0; + if (*string == 0) return -1; + uint32 c; + while ((c = *string++ - '0') <= 9) { + value = value * 10 + c; + } + return value; +} + + +#endif -- cgit v1.2.1