64 |
64 |
65 if (index + count > s.len + 1) { |
65 if (index + count > s.len + 1) { |
66 count = s.len + 1 - index; |
66 count = s.len + 1 - index; |
67 } |
67 } |
68 |
68 |
69 memcpy(result.s + 1, s.s + index - 1, count); |
69 memcpy(result.s + 1, s.s + index, count); |
70 |
70 |
71 result.len = count; |
71 result.len = count; |
72 |
72 |
73 return result; |
73 return result; |
74 } |
74 } |
75 |
75 |
76 void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
76 void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
77 // number of chars to be move |
77 // number of chars to be move |
78 int num_move; |
78 int num_move; |
79 int new_length; |
79 int new_length; |
80 |
80 |
81 string255 temp = *s; |
|
82 |
|
83 if (index < 1) { |
81 if (index < 1) { |
84 // in fpc, if index < 1, the string won't be modified |
82 // in fpc, if index < 1, the string won't be modified |
85 return; |
83 return; |
86 } |
84 } |
87 |
85 |
88 if(index > s->len){ |
86 if(index > s->len){ |
89 return; |
87 return; |
90 } |
88 } |
91 |
89 |
92 if (count > s->len - index + 1) { |
90 if (count > s->len - index + 1) { |
93 s->str[index - 1] = 0; |
|
94 s->len = index - 1; |
91 s->len = index - 1; |
95 return; |
92 return; |
96 } |
93 } |
97 |
94 |
98 num_move = s->len - index + 1 - count; |
95 num_move = s->len - index + 1 - count; |
99 new_length = s->len - count; |
96 new_length = s->len - count; |
100 |
97 |
101 memmove(s->str + index - 1, temp.str + index - 1 + count, num_move); |
98 memmove(s->str + index - 1, s->str + index - 1 + count, num_move); |
102 s->str[new_length] = 0; |
99 s->str[new_length] = 0; |
|
100 |
|
101 s->len = new_length; |
|
102 |
|
103 } |
|
104 |
|
105 void __attribute__((overloadable)) fpcrtl_delete__vars(astring *s, SizeInt index, SizeInt count) { |
|
106 // number of chars to be move |
|
107 int num_move; |
|
108 int new_length; |
|
109 |
|
110 if (index < 1) { |
|
111 // in fpc, if index < 1, the string won't be modified |
|
112 return; |
|
113 } |
|
114 |
|
115 if(index > s->len){ |
|
116 return; |
|
117 } |
|
118 |
|
119 if (count > s->len - index + 1) { |
|
120 s->len = index - 1; |
|
121 return; |
|
122 } |
|
123 |
|
124 num_move = s->len - index + 1 - count; |
|
125 new_length = s->len - count; |
|
126 |
|
127 memmove(s->s + index, s->s + index + count, num_move); |
103 |
128 |
104 s->len = new_length; |
129 s->len = new_length; |
105 |
130 |
106 } |
131 } |
107 |
132 |