Fennel: /home/pub/open/dev/fennel/calculator/SqlString.cpp Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 #include "fennel/common/CommonPreamble.h" 00028 #include "fennel/calculator/SqlString.h" 00029 00030 FENNEL_BEGIN_NAMESPACE 00031 00032 int 00033 SqlStrCat( 00034 char* dest, 00035 int destStorageBytes, 00036 int destLenBytes, 00037 char const * const str, 00038 int strLenBytes) 00039 { 00040 if (destLenBytes + strLenBytes > destStorageBytes) { 00041
00042 throw "22001"; 00043 } 00044 00045 memcpy(dest + destLenBytes, str, strLenBytes); 00046 return destLenBytes + strLenBytes; 00047 } 00048 00049 00050 int 00051 SqlStrCat( 00052 char* dest, 00053 int destStorageBytes, 00054 char const * const str1, 00055 int str1LenBytes, 00056 char const * const str2, 00057 int str2LenBytes) 00058 { 00059 if (str1LenBytes + str2LenBytes > destStorageBytes) { 00060
00061
00062 throw "22001"; 00063 } 00064 00065 memcpy(dest, str1, str1LenBytes); 00066 memcpy(dest + str1LenBytes, str2, str2LenBytes); 00067 return str1LenBytes + str2LenBytes; 00068 } 00069 00070 int 00071 SqlStrCmp_Bin( 00072 char const * const str1, 00073 int str1LenBytes, 00074 char const * const str2, 00075 int str2LenBytes) 00076 { 00077
00078
00079 int minLenBytes = 00080 str1LenBytes > str2LenBytes ? str2LenBytes : str1LenBytes; 00081 int memc = memcmp(str1, str2, minLenBytes); 00082 if (memc > 0) { 00083
00084 return 1; 00085 } else if (memc < 0) { 00086
00087 return -1; 00088 } else if (str1LenBytes == str2LenBytes) { 00089
00090
00091 return 0; 00092 } else if (str1LenBytes > str2LenBytes) { 00093
00094 return 1; 00095 } else { 00096
00097 return -1; 00098 } 00099 } 00100 00101 int 00102 SqlStrCpy_Var( 00103 char* dest, 00104 int destStorageBytes, 00105 char const * const str, 00106 int strLenBytes) 00107 { 00108 if (strLenBytes > destStorageBytes) { 00109
00110
00111 throw "22001"; 00112 } 00113 memcpy(dest, str, strLenBytes); 00114 return strLenBytes; 00115 } 00116 00117 int 00118 SqlStrLenBit(int strLenBytes) 00119 { 00120 return 8 * strLenBytes; 00121 } 00122 00123 int 00124 SqlStrLenOct(int strLenBytes) 00125 { 00126 return strLenBytes; 00127 } 00128 00129 00130 FENNEL_END_NAMESPACE 00131 00132