@@ -819,25 +819,13 @@ mbfl_strpos(
819819 size_t result ;
820820 mbfl_string _haystack_u8 , _needle_u8 ;
821821 const mbfl_string * haystack_u8 , * needle_u8 = NULL ;
822- const unsigned char * u8_tbl ;
823-
824- if (haystack == NULL || haystack -> val == NULL || needle == NULL || needle -> val == NULL ) {
825- return (size_t ) -8 ;
826- }
827-
828- {
829- const mbfl_encoding * u8_enc = & mbfl_encoding_utf8 ;
830- if (u8_enc -> mblen_table == NULL ) {
831- return (size_t ) -8 ;
832- }
833- u8_tbl = u8_enc -> mblen_table ;
834- }
822+ const unsigned char * u8_tbl = mbfl_encoding_utf8 .mblen_table ;
835823
836824 if (haystack -> encoding -> no_encoding != mbfl_no_encoding_utf8 ) {
837825 mbfl_string_init (& _haystack_u8 );
838826 haystack_u8 = mbfl_convert_encoding (haystack , & _haystack_u8 , & mbfl_encoding_utf8 );
839827 if (haystack_u8 == NULL ) {
840- result = ( size_t ) -4 ;
828+ result = MBFL_ERROR_ENCODING ;
841829 goto out ;
842830 }
843831 } else {
@@ -848,14 +836,14 @@ mbfl_strpos(
848836 mbfl_string_init (& _needle_u8 );
849837 needle_u8 = mbfl_convert_encoding (needle , & _needle_u8 , & mbfl_encoding_utf8 );
850838 if (needle_u8 == NULL ) {
851- result = ( size_t ) -4 ;
839+ result = MBFL_ERROR_ENCODING ;
852840 goto out ;
853841 }
854842 } else {
855843 needle_u8 = needle ;
856844 }
857845
858- result = ( size_t ) -1 ;
846+ result = MBFL_ERROR_NOT_FOUND ;
859847 if (haystack_u8 -> len < needle_u8 -> len ) {
860848 goto out ;
861849 }
@@ -898,7 +886,7 @@ mbfl_strpos(
898886 p = haystack_u8_val ;
899887 while (offset -- > 0 ) {
900888 if (p >= e ) {
901- result = ( size_t ) -16 ;
889+ result = MBFL_ERROR_OFFSET ;
902890 goto out ;
903891 }
904892 p += u8_tbl [* p ];
@@ -968,7 +956,7 @@ mbfl_strpos(
968956 while (offset < 0 ) {
969957 unsigned char c ;
970958 if (p <= e ) {
971- result = ( size_t ) -16 ;
959+ result = MBFL_ERROR_OFFSET ;
972960 goto out ;
973961 }
974962 c = * (-- p );
@@ -983,7 +971,7 @@ mbfl_strpos(
983971 const unsigned char * ee = haystack_u8_val + haystack_u8 -> len ;
984972 while (offset -- > 0 ) {
985973 if (e >= ee ) {
986- result = ( size_t ) -16 ;
974+ result = MBFL_ERROR_OFFSET ;
987975 goto out ;
988976 }
989977 e += u8_tbl [* e ];
@@ -1046,28 +1034,25 @@ mbfl_substr_count(
10461034 mbfl_convert_filter * filter ;
10471035 struct collector_strpos_data pc ;
10481036
1049- if (haystack == NULL || needle == NULL ) {
1050- return (size_t ) -8 ;
1051- }
10521037 /* needle is converted into wchar */
10531038 mbfl_wchar_device_init (& pc .needle );
10541039 filter = mbfl_convert_filter_new (
10551040 needle -> encoding ,
10561041 & mbfl_encoding_wchar ,
10571042 mbfl_wchar_device_output , 0 , & pc .needle );
10581043 if (filter == NULL ) {
1059- return ( size_t ) -4 ;
1044+ return MBFL_ERROR_ENCODING ;
10601045 }
10611046 mbfl_convert_filter_feed_string (filter , needle -> val , needle -> len );
10621047 mbfl_convert_filter_flush (filter );
10631048 mbfl_convert_filter_delete (filter );
10641049 pc .needle_len = pc .needle .pos ;
10651050 if (pc .needle .buffer == NULL ) {
1066- return ( size_t ) -4 ;
1051+ return MBFL_ERROR_ENCODING ;
10671052 }
1068- if (pc .needle_len < = 0 ) {
1053+ if (pc .needle_len = = 0 ) {
10691054 mbfl_wchar_device_clear (& pc .needle );
1070- return ( size_t ) -2 ;
1055+ return MBFL_ERROR_EMPTY ;
10711056 }
10721057 /* initialize filter and collector data */
10731058 filter = mbfl_convert_filter_new (
@@ -1076,26 +1061,26 @@ mbfl_substr_count(
10761061 collector_strpos , 0 , & pc );
10771062 if (filter == NULL ) {
10781063 mbfl_wchar_device_clear (& pc .needle );
1079- return ( size_t ) -4 ;
1064+ return MBFL_ERROR_ENCODING ;
10801065 }
10811066 pc .start = 0 ;
10821067 pc .output = 0 ;
10831068 pc .needle_pos = 0 ;
10841069 pc .found_pos = 0 ;
1085- pc .matched_pos = ( size_t ) -1 ;
1070+ pc .matched_pos = MBFL_ERROR_NOT_FOUND ;
10861071
10871072 /* feed data */
10881073 p = haystack -> val ;
10891074 n = haystack -> len ;
10901075 if (p != NULL ) {
10911076 while (n > 0 ) {
10921077 if ((* filter -> filter_function )(* p ++ , filter ) < 0 ) {
1093- pc .matched_pos = ( size_t ) -4 ;
1078+ pc .matched_pos = MBFL_ERROR_ENCODING ;
10941079 break ;
10951080 }
1096- if (pc .matched_pos != ( size_t ) -1 ) {
1081+ if (pc .matched_pos != MBFL_ERROR_NOT_FOUND ) {
10971082 ++ result ;
1098- pc .matched_pos = ( size_t ) -1 ;
1083+ pc .matched_pos = MBFL_ERROR_NOT_FOUND ;
10991084 pc .needle_pos = 0 ;
11001085 }
11011086 n -- ;
0 commit comments