@@ -203,12 +203,15 @@ size_t basic_string_copy(const basic_string_t* cpt_basic_string, void* pv_buffer
203
203
pby_pos = cpt_basic_string -> _pby_string + t_pos * t_typesize ;
204
204
pby_terminator = cpt_basic_string -> _pby_string + basic_string_size (cpt_basic_string ) * t_typesize ;
205
205
206
- /*
207
- * It does not require judgment terminator,
208
- * when the type style is c built-in type,
209
- * which improves efficiency.
210
- */
211
- if (_GET_BASIC_STRING_TYPE_STYLE (cpt_basic_string ) == _TYPE_C_BUILTIN ) {
206
+ if (strncmp (_GET_BASIC_STRING_TYPE_BASENAME (cpt_basic_string ), _C_STRING_TYPE , _TYPE_NAME_SIZE ) == 0 ) {
207
+ for (i = 0 ; i < t_size ; ++ i ) {
208
+ if (memcmp (pby_terminator , pby_pos + i * t_typesize , t_typesize ) != 0 ) {
209
+ * ((const char * * )pv_buffer + i ) = string_c_str ((string_t * )(pby_pos + i * t_typesize ));
210
+ } else {
211
+ * ((const char * * )pv_buffer + i ) = NULL ;
212
+ }
213
+ }
214
+ } else if (_GET_BASIC_STRING_TYPE_STYLE (cpt_basic_string ) == _TYPE_C_BUILTIN ) {
212
215
for (i = 0 ; i < t_size ; ++ i ) {
213
216
b_result = _GET_BASIC_STRING_TYPE_SIZE (cpt_basic_string );
214
217
_GET_BASIC_STRING_TYPE_COPY_FUNCTION (cpt_basic_string )(
@@ -217,8 +220,11 @@ size_t basic_string_copy(const basic_string_t* cpt_basic_string, void* pv_buffer
217
220
}
218
221
} else {
219
222
for (i = 0 ; i < t_size ; ++ i ) {
220
- _basic_string_copy_elem_with_terminator (
221
- cpt_basic_string , (_byte_t * )pv_buffer + i * t_typesize , pby_pos + i * t_typesize , pby_terminator );
223
+ if (memcmp (pby_terminator , pby_pos + i * t_typesize , t_typesize ) != 0 ) {
224
+ * ((const _byte_t * * )pv_buffer + i ) = pby_pos + i * t_typesize ;
225
+ } else {
226
+ * ((const _byte_t * * )pv_buffer + i ) = NULL ;
227
+ }
222
228
}
223
229
}
224
230
@@ -445,7 +451,8 @@ int basic_string_compare_substring_substring(
445
451
pby_first = cpt_first -> _pby_string + t_firstpos * t_typesize ;
446
452
pby_second = cpt_second -> _pby_string + t_secondpos * t_typesize ;
447
453
pby_terminator = cpt_first -> _pby_string + basic_string_size (cpt_first ) * t_typesize ;
448
- if (_GET_BASIC_STRING_TYPE_STYLE (cpt_first ) == _TYPE_CSTL_BUILTIN ) {
454
+ if (_GET_BASIC_STRING_TYPE_STYLE (cpt_first ) == _TYPE_CSTL_BUILTIN ||
455
+ strncmp (_GET_BASIC_STRING_TYPE_BASENAME (cpt_first ), _C_STRING_TYPE , _TYPE_NAME_SIZE ) == 0 ) {
449
456
for (i = 0 ; i < t_cmplen ; ++ i ) {
450
457
int n_first = memcmp (pby_terminator , pby_first , t_typesize );
451
458
int n_second = memcmp (pby_terminator , pby_second , t_typesize );
@@ -554,9 +561,18 @@ int basic_string_compare_substring_subcstr(
554
561
/* char* */
555
562
if (strncmp (_GET_BASIC_STRING_TYPE_BASENAME (cpt_basic_string ), _C_STRING_TYPE , _TYPE_NAME_SIZE ) == 0 ) {
556
563
for (i = 0 ; i < t_cmplen ; ++ i ) {
557
- int n_result = string_compare_cstr ((string_t * )(pby_string + i * t_typesize ), * ((char * * )cpv_value_string + i ));
558
- if (n_result != 0 ) {
559
- return n_result ;
564
+ int n_result = memcmp (pby_terminator , pby_string + i * t_typesize , t_typesize );
565
+
566
+ if (n_result == 0 && * ((char * * )cpv_value_string + i ) != NULL ) {
567
+ return -1 ;
568
+ } else if (n_result != 0 && * ((char * * )cpv_value_string + i ) == NULL ) {
569
+ return 1 ;
570
+ } else if (n_result != 0 && * ((char * * )cpv_value_string + i ) != NULL ) {
571
+ int n_cmp_result = string_compare_cstr (
572
+ (string_t * )(pby_string + i * t_typesize ), * ((char * * )cpv_value_string + i ));
573
+ if (n_cmp_result != 0 ) {
574
+ return n_cmp_result ;
575
+ }
560
576
}
561
577
}
562
578
} else if (_GET_BASIC_STRING_TYPE_STYLE (cpt_basic_string ) == _TYPE_C_BUILTIN ) {
0 commit comments