316 /***************/ |
316 /***************/ |
317 /* String ops */ |
317 /* String ops */ |
318 /***************/ |
318 /***************/ |
319 #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) |
319 #define __STR_CMP(str1, str2) memcmp((char*)&str1.body,(char*)&str2.body, str1.len < str2.len ? str1.len : str2.len) |
320 |
320 |
321 static inline UINT __len(EN_ENO_PARAMS, STRING IN){ |
321 static inline __strlen_t __len(EN_ENO_PARAMS, STRING IN){ |
322 TEST_EN(UINT) |
322 TEST_EN(UINT) |
323 return IN.len; |
323 return IN.len; |
324 } |
324 } |
325 static inline STRING __left(EN_ENO_PARAMS, STRING IN, SINT L){ |
325 static inline STRING __left(EN_ENO_PARAMS, STRING IN, __strlen_t L){ |
326 TEST_EN_COND(STRING, L < 0) |
326 TEST_EN_COND(STRING, L < 0) |
327 STRING res = __INIT_STRING; |
327 STRING res = __INIT_STRING; |
328 L = L < IN.len ? L : IN.len; |
328 L = L < IN.len ? L : IN.len; |
329 memcpy(&res.body, &IN.body, L); |
329 memcpy(&res.body, &IN.body, L); |
330 res.len = L; |
330 res.len = L; |
331 return res; |
331 return res; |
332 } |
332 } |
333 static inline STRING __right(EN_ENO_PARAMS, STRING IN, SINT L){ |
333 static inline STRING __right(EN_ENO_PARAMS, STRING IN, __strlen_t L){ |
334 TEST_EN_COND(STRING, L < 0) |
334 TEST_EN_COND(STRING, L < 0) |
335 STRING res = __INIT_STRING; |
335 STRING res = __INIT_STRING; |
336 L = L < IN.len ? L : IN.len; |
336 L = L < IN.len ? L : IN.len; |
337 memcpy(&res.body, &IN.body[IN.len - L], L); |
337 memcpy(&res.body, &IN.body[IN.len - L], L); |
338 res.len = L; |
338 res.len = L; |
339 return res; |
339 return res; |
340 } |
340 } |
341 static inline STRING __mid(EN_ENO_PARAMS, STRING IN, SINT L, SINT P){ |
341 static inline STRING __mid(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){ |
342 TEST_EN_COND(STRING, L < 0 || P < 0) |
342 TEST_EN_COND(STRING, L < 0 || P < 0) |
343 STRING res = __INIT_STRING; |
343 STRING res = __INIT_STRING; |
344 if(P <= IN.len){ |
344 if(P <= IN.len){ |
345 P -= 1; /* now can be used as [index]*/ |
345 P -= 1; /* now can be used as [index]*/ |
346 L = L + P <= IN.len ? L : IN.len - P; |
346 L = L + P <= IN.len ? L : IN.len - P; |
347 memcpy(&res.body, &IN.body[P] , L); |
347 memcpy(&res.body, &IN.body[P] , L); |
348 res.len = L; |
348 res.len = L; |
349 } |
349 } |
350 return res; |
350 return res; |
351 } |
351 } |
352 static inline STRING __concat(EN_ENO_PARAMS, SINT param_count, ...){ |
352 static inline STRING __concat(EN_ENO_PARAMS, UINT param_count, ...){ |
353 TEST_EN(STRING) |
353 TEST_EN(STRING) |
354 va_list ap; |
354 va_list ap; |
355 UINT i; |
355 UINT i; |
356 __strlen_t charcount = 0; |
356 __strlen_t charcount = 0; |
357 STRING res = __INIT_STRING; |
357 STRING res = __INIT_STRING; |
370 res.len = charcount; |
370 res.len = charcount; |
371 |
371 |
372 va_end (ap); /* Clean up. */ |
372 va_end (ap); /* Clean up. */ |
373 return res; |
373 return res; |
374 } |
374 } |
375 static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, SINT P){ |
375 static inline STRING __insert(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t P){ |
376 TEST_EN_COND(STRING, P < 0) |
376 TEST_EN_COND(STRING, P < 0) |
377 STRING res = __INIT_STRING; |
377 STRING res = __INIT_STRING; |
378 __strlen_t to_copy; |
378 __strlen_t to_copy; |
379 |
379 |
380 to_copy = P > IN1.len ? IN1.len : P - 1; |
380 to_copy = P > IN1.len ? IN1.len : P - 1; |
389 memcpy(&res.body[res.len], &IN1.body[P] , to_copy); |
389 memcpy(&res.body[res.len], &IN1.body[P] , to_copy); |
390 res.len += to_copy; |
390 res.len += to_copy; |
391 |
391 |
392 return res; |
392 return res; |
393 } |
393 } |
394 static inline STRING __delete(EN_ENO_PARAMS, STRING IN, SINT L, SINT P){ |
394 static inline STRING __delete(EN_ENO_PARAMS, STRING IN, __strlen_t L, __strlen_t P){ |
395 TEST_EN_COND(STRING, L < 0 || P < 0) |
395 TEST_EN_COND(STRING, L < 0 || P < 0) |
396 STRING res = __INIT_STRING; |
396 STRING res = __INIT_STRING; |
397 __strlen_t to_copy; |
397 __strlen_t to_copy; |
398 |
398 |
399 to_copy = P > IN.len ? IN.len : P-1; |
399 to_copy = P > IN.len ? IN.len : P-1; |
406 res.len += to_copy; |
406 res.len += to_copy; |
407 } |
407 } |
408 |
408 |
409 return res; |
409 return res; |
410 } |
410 } |
411 static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, SINT L, SINT P){ |
411 static inline STRING __replace(EN_ENO_PARAMS, STRING IN1, STRING IN2, __strlen_t L, __strlen_t P){ |
412 TEST_EN_COND(STRING, L < 0 || P < 0) |
412 TEST_EN_COND(STRING, L < 0 || P < 0) |
413 STRING res = __INIT_STRING; |
413 STRING res = __INIT_STRING; |
414 __strlen_t to_copy; |
414 __strlen_t to_copy; |
415 |
415 |
416 to_copy = P > IN1.len ? IN1.len : P-1; |
416 to_copy = P > IN1.len ? IN1.len : P-1; |