Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/string.h
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/string.h
r321 r331 8 8 #define MRUBY_STRING_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /** … … 45 45 if (RSTR_EMBED_P(s)) {\ 46 46 RSTR_SET_EMBED_LEN((s),(n));\ 47 } else {\ 47 }\ 48 else {\ 48 49 s->as.heap.len = (mrb_int)(n);\ 49 50 }\ … … 63 64 #define RSTR_UNSET_NOFREE_FLAG(s) ((s)->flags &= ~MRB_STR_NOFREE) 64 65 65 #define RSTR_FROZEN_P(s) ((s)->flags & MRB_STR_FROZEN)66 #define RSTR_SET_FROZEN_FLAG(s) ((s)->flags |= MRB_STR_FROZEN)67 #define RSTR_UNSET_FROZEN_FLAG(s) ((s)->flags &= ~MRB_STR_FROZEN)68 69 66 /* 70 67 * Returns a pointer from a Ruby string … … 73 70 #define RSTRING(s) mrb_str_ptr(s) 74 71 #define RSTRING_PTR(s) RSTR_PTR(RSTRING(s)) 75 #define RSTRING_EMBED_LEN(s) RSTR_E NBED_LEN(RSTRING(s))72 #define RSTRING_EMBED_LEN(s) RSTR_EMBED_LEN(RSTRING(s)) 76 73 #define RSTRING_LEN(s) RSTR_LEN(RSTRING(s)) 77 74 #define RSTRING_CAPA(s) RSTR_CAPA(RSTRING(s)) 78 75 #define RSTRING_END(s) (RSTRING_PTR(s) + RSTRING_LEN(s)) 79 mrb_int mrb_str_strlen(mrb_state*, struct RString*);76 MRB_API mrb_int mrb_str_strlen(mrb_state*, struct RString*); 80 77 81 78 #define MRB_STR_SHARED 1 82 79 #define MRB_STR_NOFREE 2 83 #define MRB_STR_ FROZEN 484 #define MRB_STR_EMBED 885 #define MRB_STR_EMBED_LEN_MASK 0x 1f086 #define MRB_STR_EMBED_LEN_SHIFT 480 #define MRB_STR_NO_UTF 8 81 #define MRB_STR_EMBED 16 82 #define MRB_STR_EMBED_LEN_MASK 0x3e0 83 #define MRB_STR_EMBED_LEN_SHIFT 5 87 84 88 85 void mrb_gc_free_str(mrb_state*, struct RString*); 89 86 MRB_API void mrb_str_modify(mrb_state*, struct RString*); 87 /* 88 * Appends self to other. Returns self as a concatnated string. 89 * 90 * 91 * Example: 92 * 93 * !!!c 94 * int 95 * main(int argc, 96 * char **argv) 97 * { 98 * // Variable declarations. 99 * mrb_value str1; 100 * mrb_value str2; 101 * 102 * mrb_state *mrb = mrb_open(); 103 * if (!mrb) 104 * { 105 * // handle error 106 * } 107 * 108 * // Creates new Ruby strings. 109 * str1 = mrb_str_new_lit(mrb, "abc"); 110 * str2 = mrb_str_new_lit(mrb, "def"); 111 * 112 * // Concatnates str2 to str1. 113 * mrb_str_concat(mrb, str1, str2); 114 * 115 * // Prints new Concatnated Ruby string. 116 * mrb_p(mrb, str1); 117 * 118 * mrb_close(mrb); 119 * return 0; 120 * } 121 * 122 * 123 * Result: 124 * 125 * => "abcdef" 126 * 127 * @param [mrb_state] mrb The current mruby state. 128 * @param [mrb_value] self String to concatenate. 129 * @param [mrb_value] other String to append to self. 130 * @return [mrb_value] Returns a new String appending other to self. 131 */ 90 132 MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value); 91 133 92 134 /* 93 135 * Adds two strings together. 136 * 137 * 138 * Example: 139 * 140 * !!!c 141 * int 142 * main(int argc, 143 * char **argv) 144 * { 145 * // Variable declarations. 146 * mrb_value a; 147 * mrb_value b; 148 * mrb_value c; 149 * 150 * mrb_state *mrb = mrb_open(); 151 * if (!mrb) 152 * { 153 * // handle error 154 * } 155 * 156 * // Creates two Ruby strings from the passed in C strings. 157 * a = mrb_str_new_lit(mrb, "abc"); 158 * b = mrb_str_new_lit(mrb, "def"); 159 * 160 * // Prints both C strings. 161 * mrb_p(mrb, a); 162 * mrb_p(mrb, b); 163 * 164 * // Concatnates both Ruby strings. 165 * c = mrb_str_plus(mrb, a, b); 166 * 167 * // Prints new Concatnated Ruby string. 168 * mrb_p(mrb, c); 169 * 170 * mrb_close(mrb); 171 * return 0; 172 * } 173 * 174 * 175 * Result: 176 * 177 * => "abc" # First string 178 * => "def" # Second string 179 * => "abcdef" # First & Second concatnated. 180 * 181 * @param [mrb_state] mrb The current mruby state. 182 * @param [mrb_value] a First string to concatenate. 183 * @param [mrb_value] b Second string to concatenate. 184 * @return [mrb_value] Returns a new String containing a concatenated to b. 94 185 */ 95 186 MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value); … … 97 188 /* 98 189 * Converts pointer into a Ruby string. 190 * 191 * @param [mrb_state] mrb The current mruby state. 192 * @param [void*] p The pointer to convert to Ruby string. 193 * @return [mrb_value] Returns a new Ruby String. 99 194 */ 100 195 MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*); … … 102 197 /* 103 198 * Returns an object as a Ruby string. 199 * 200 * @param [mrb_state] mrb The current mruby state. 201 * @param [mrb_value] obj An object to return as a Ruby string. 202 * @return [mrb_value] An object as a Ruby string. 104 203 */ 105 204 MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj); 106 205 107 206 /* 108 * Resizes the string's length. 207 * Resizes the string's length. Returns the amount of characters 208 * in the specified by len. 209 * 210 * Example: 211 * 212 * !!!c 213 * int 214 * main(int argc, 215 * char **argv) 216 * { 217 * // Variable declaration. 218 * mrb_value str; 219 * 220 * mrb_state *mrb = mrb_open(); 221 * if (!mrb) 222 * { 223 * // handle error 224 * } 225 * // Creates a new string. 226 * str = mrb_str_new_lit(mrb, "Hello, world!"); 227 * // Returns 5 characters of 228 * mrb_str_resize(mrb, str, 5); 229 * mrb_p(mrb, str); 230 * 231 * mrb_close(mrb); 232 * return 0; 233 * } 234 * 235 * Result: 236 * 237 * => "Hello" 238 * 239 * @param [mrb_state] mrb The current mruby state. 240 * @param [mrb_value] str The Ruby string to resize. 241 * @param [mrb_value] len The length. 242 * @return [mrb_value] An object as a Ruby string. 109 243 */ 110 244 MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len); … … 112 246 /* 113 247 * Returns a sub string. 248 * 249 * Example: 250 * 251 * !!!c 252 * int 253 * main(int argc, 254 * char const **argv) 255 * { 256 * // Variable declarations. 257 * mrb_value str1; 258 * mrb_value str2; 259 * 260 * mrb_state *mrb = mrb_open(); 261 * if (!mrb) 262 * { 263 * // handle error 264 * } 265 * // Creates new string. 266 * str1 = mrb_str_new_lit(mrb, "Hello, world!"); 267 * // Returns a sub-string within the range of 0..2 268 * str2 = mrb_str_substr(mrb, str1, 0, 2); 269 * 270 * // Prints sub-string. 271 * mrb_p(mrb, str2); 272 * 273 * mrb_close(mrb); 274 * return 0; 275 * } 276 * 277 * Result: 278 * 279 * => "He" 280 * 281 * @param [mrb_state] mrb The current mruby state. 282 * @param [mrb_value] str Ruby string. 283 * @param [mrb_int] beg The beginning point of the sub-string. 284 * @param [mrb_int] len The end point of the sub-string. 285 * @return [mrb_value] An object as a Ruby sub-string. 114 286 */ 115 287 MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len); … … 117 289 /* 118 290 * Returns a Ruby string type. 291 * 292 * 293 * @param [mrb_state] mrb The current mruby state. 294 * @param [mrb_value] str Ruby string. 295 * @return [mrb_value] A Ruby string. 119 296 */ 120 297 MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str); … … 124 301 125 302 MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr); 126 MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value ptr); 303 MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str); 304 /* 305 * Returns the length of the Ruby string. 306 * 307 * 308 * @param [mrb_state] mrb The current mruby state. 309 * @param [mrb_value] str Ruby string. 310 * @return [mrb_int] The length of the passed in Ruby string. 311 */ 312 MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str); 127 313 128 314 /* 129 315 * Duplicates a string object. 316 * 317 * 318 * @param [mrb_state] mrb The current mruby state. 319 * @param [mrb_value] str Ruby string. 320 * @return [mrb_value] Duplicated Ruby string. 130 321 */ 131 322 MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str); 132 323 133 324 /* 134 * Returns a symbol from a passed in string. 325 * Returns a symbol from a passed in Ruby string. 326 * 327 * @param [mrb_state] mrb The current mruby state. 328 * @param [mrb_value] self Ruby string. 329 * @return [mrb_value] A symbol. 135 330 */ 136 331 MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self); … … 146 341 /* 147 342 * Returns true if the strings match and false if the strings don't match. 343 * 344 * @param [mrb_state] mrb The current mruby state. 345 * @param [mrb_value] str1 Ruby string to compare. 346 * @param [mrb_value] str2 Ruby string to compare. 347 * @return [mrb_value] boolean value. 148 348 */ 149 349 MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2); … … 152 352 * Returns a concated string comprised of a Ruby string and a C string. 153 353 * 354 * @param [mrb_state] mrb The current mruby state. 355 * @param [mrb_value] str Ruby string. 356 * @param [const char *] ptr A C string. 357 * @param [size_t] len length of C string. 358 * @return [mrb_value] A Ruby string. 154 359 * @see mrb_str_cat_cstr 155 360 */ … … 159 364 * Returns a concated string comprised of a Ruby string and a C string. 160 365 * 366 * @param [mrb_state] mrb The current mruby state. 367 * @param [mrb_value] str Ruby string. 368 * @param [const char *] ptr A C string. 369 * @return [mrb_value] A Ruby string. 161 370 * @see mrb_str_cat 162 371 */ … … 176 385 177 386 /* 178 * Returns a C string from a Ruby string. 387 * Returns a newly allocated C string from a Ruby string. 388 * This is an utility function to pass a Ruby string to C library functions. 389 * 390 * - Returned string does not contain any NUL characters (but terminator). 391 * - It raises an ArgumentError exception if Ruby string contains 392 * NUL characters. 393 * - Retured string will be freed automatically on next GC. 394 * - Caller can modify returned string without affecting Ruby string 395 * (e.g. it can be used for mkstemp(3)). 396 * 397 * @param [mrb_state *] mrb The current mruby state. 398 * @param [mrb_value] str Ruby string. Must be an instance of String. 399 * @return [char *] A newly allocated C string. 179 400 */ 180 401 MRB_API char *mrb_str_to_cstr(mrb_state *mrb, mrb_value str);
Note:
See TracChangeset
for help on using the changeset viewer.