comparison src/misc2.c @ 323:03b3684919e3 v7.0084

updated for version 7.0084
author vimboss
date Mon, 13 Jun 2005 22:28:56 +0000
parents 96a9bfba3880
children d5e895294dce
comparison
equal deleted inserted replaced
322:a18bd33b8ea9 323:03b3684919e3
1080 *p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20); 1080 *p2++ = (c < 'a' || c > 'z') ? c : (c - 0x20);
1081 #endif 1081 #endif
1082 } 1082 }
1083 } 1083 }
1084 1084
1085 #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) || defined(PROTO)
1086 /*
1087 * Make string "s" all upper-case and return it in allocated memory.
1088 * Handles multi-byte characters as well as possible.
1089 * Returns NULL when out of memory.
1090 */
1091 char_u *
1092 strup_save(orig)
1093 char_u *orig;
1094 {
1095 char_u *p;
1096 char_u *res;
1097
1098 res = p = vim_strsave(orig);
1099
1100 if (res != NULL)
1101 while (*p != NUL)
1102 {
1103 # ifdef FEAT_MBYTE
1104 int l;
1105
1106 if (enc_utf8)
1107 {
1108 int c, uc;
1109 int nl;
1110 char_u *s;
1111
1112 c = utf_ptr2char(p);
1113 uc = utf_toupper(c);
1114
1115 /* Reallocate string when byte count changes. This is rare,
1116 * thus it's OK to do another malloc()/free(). */
1117 l = utf_ptr2len_check(p);
1118 nl = utf_char2len(uc);
1119 if (nl != l)
1120 {
1121 s = alloc((unsigned)STRLEN(res) + 1 + nl - l);
1122 if (s == NULL)
1123 break;
1124 mch_memmove(s, res, p - res);
1125 STRCPY(s + (p - res) + nl, p + l);
1126 p = s + (p - res);
1127 vim_free(res);
1128 res = s;
1129 }
1130
1131 utf_char2bytes(uc, p);
1132 p += nl;
1133 }
1134 else if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
1135 p += l; /* skip multi-byte character */
1136 else
1137 # endif
1138 {
1139 *p = TOUPPER_LOC(*p); /* note that toupper() can be a macro */
1140 p++;
1141 }
1142 }
1143
1144 return res;
1145 }
1146 #endif
1147
1085 /* 1148 /*
1086 * copy a space a number of times 1149 * copy a space a number of times
1087 */ 1150 */
1088 void 1151 void
1089 copy_spaces(ptr, count) 1152 copy_spaces(ptr, count)
1129 while (--q > ptr && vim_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V) 1192 while (--q > ptr && vim_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V)
1130 *q = NUL; 1193 *q = NUL;
1131 } 1194 }
1132 1195
1133 /* 1196 /*
1134 * This is here because strncpy() does not guarantee successful results when 1197 * Like strncpy(), but always terminate the result with one NUL.
1135 * the to and from strings overlap. It is only currently called from
1136 * nextwild() which copies part of the command line to another part of the
1137 * command line. This produced garbage when expanding files etc in the middle
1138 * of the command line (on my terminal, anyway) -- webb.
1139 * Note: strncpy() pads the remainder of the buffer with NUL bytes,
1140 * vim_strncpy() doesn't do that.
1141 */ 1198 */
1142 void 1199 void
1143 vim_strncpy(to, from, len) 1200 vim_strncpy(to, from, len)
1144 char_u *to; 1201 char_u *to;
1145 char_u *from; 1202 char_u *from;
1146 int len; 1203 int len;
1147 { 1204 {
1148 int i; 1205 STRNCPY(to, from, len);
1149 1206 to[len] = NUL;
1150 if (to <= from)
1151 {
1152 while (len-- && *from)
1153 *to++ = *from++;
1154 if (len >= 0)
1155 *to = *from; /* Copy NUL */
1156 }
1157 else
1158 {
1159 for (i = 0; i < len; i++)
1160 {
1161 to++;
1162 if (*from++ == NUL)
1163 {
1164 i++;
1165 break;
1166 }
1167 }
1168 for (; i > 0; i--)
1169 *--to = *--from;
1170 }
1171 } 1207 }
1172 1208
1173 /* 1209 /*
1174 * Isolate one part of a string option where parts are separated with 1210 * Isolate one part of a string option where parts are separated with
1175 * "sep_chars". 1211 * "sep_chars".