69 memcpy(result.s + 1, s.s + index, 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 } |
|
75 |
|
76 void fpcrtl_insert__vars(string255 *src, string255 *dst, SizeInt index) { |
|
77 int num_insert; |
|
78 int num_shift; |
|
79 int num_preshift; |
|
80 |
|
81 // nothing to do if empty string is inserted or index invalid |
|
82 if ((src->len == 0) || (index < 1) || (index > 255)) { |
|
83 return; |
|
84 } |
|
85 |
|
86 num_insert = src->len; |
|
87 // number of chars from start of destination string to end of insertion |
|
88 num_preshift = index - 1 + num_insert; |
|
89 |
|
90 // don't overflow on insert |
|
91 if (num_preshift > 255) { |
|
92 num_insert = 255 - (index - 1); |
|
93 num_shift = 0; |
|
94 } |
|
95 // shift trailing chars |
|
96 else { |
|
97 // number of bytes to be shifted |
|
98 num_shift = dst->len - (index - 1); |
|
99 |
|
100 if (num_shift > 0) { |
|
101 // don't overflow when shifting |
|
102 if (num_shift + num_preshift > 255) |
|
103 num_shift = 255 - num_preshift; |
|
104 |
|
105 // time to move some bytes! |
|
106 memmove(dst->str + num_preshift, dst->str + index - 1, num_shift); |
|
107 } |
|
108 } |
|
109 |
|
110 // actual byte insertion |
|
111 memmove(dst->str + index - 1, src->str, num_insert); |
|
112 // store new length |
|
113 dst->len = num_shift + num_preshift; |
74 } |
114 } |
75 |
115 |
76 void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
116 void __attribute__((overloadable)) fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) { |
77 // number of chars to be move |
117 // number of chars to be move |
78 int num_move; |
118 int num_move; |