Skip to content

Commit 189ad47

Browse files
author
Ralph Desir(Mav7)
committed
yard docs for string.h
1 parent 97283fa commit 189ad47

File tree

1 file changed

+213
-2
lines changed

1 file changed

+213
-2
lines changed

include/mruby/string.h

+213-2
Original file line numberDiff line numberDiff line change
@@ -88,35 +88,215 @@ mrb_int mrb_str_strlen(mrb_state*, struct RString*);
8888

8989
void mrb_gc_free_str(mrb_state*, struct RString*);
9090
MRB_API void mrb_str_modify(mrb_state*, struct RString*);
91+
/*
92+
* Appends self to other. Returns self as a concatnated string.
93+
*
94+
*
95+
* Example:
96+
*
97+
* !!!c
98+
* int
99+
* main(int argc,
100+
* char **argv)
101+
* {
102+
* // Variable declarations.
103+
* mrb_value str1;
104+
* mrb_value str2;
105+
*
106+
* mrb_state *mrb = mrb_open();
107+
* if (!mrb)
108+
* {
109+
* // handle error
110+
* }
111+
*
112+
* // Creates new Ruby strings.
113+
* str1 = mrb_str_new_cstr(mrb, "abc");
114+
* str2 = mrb_str_new_cstr(mrb, "def");
115+
*
116+
* // Concatnates str2 to str1.
117+
* mrb_str_concat(mrb, str1, str2);
118+
*
119+
* // Prints new Concatnated Ruby string.
120+
* mrb_p(mrb, str1);
121+
*
122+
* mrb_close(mrb);
123+
* return 0;
124+
* }
125+
*
126+
*
127+
* Result:
128+
*
129+
* => "abcdef"
130+
*
131+
* @param [mrb_state] mrb The current mruby state.
132+
* @param [mrb_value] self String to concatenate.
133+
* @param [mrb_value] other String to append to self.
134+
* @return [mrb_value] Returns a new String appending other to self.
135+
*/
91136
MRB_API void mrb_str_concat(mrb_state*, mrb_value, mrb_value);
92137

93138
/*
94139
* Adds two strings together.
140+
*
141+
*
142+
* Example:
143+
*
144+
* !!!c
145+
* int
146+
* main(int argc,
147+
* char **argv)
148+
* {
149+
* // Variable declarations.
150+
* mrb_value a;
151+
* mrb_value b;
152+
* mrb_value c;
153+
*
154+
* mrb_state *mrb = mrb_open();
155+
* if (!mrb)
156+
* {
157+
* // handle error
158+
* }
159+
*
160+
* // Creates two Ruby strings from the passed in C strings.
161+
* a = mrb_str_new_cstr(mrb, "abc");
162+
* b = mrb_str_new_cstr(mrb, "def");
163+
*
164+
* // Prints both C strings.
165+
* mrb_p(mrb, a);
166+
* mrb_p(mrb, b);
167+
*
168+
* // Concatnates both Ruby strings.
169+
* c = mrb_str_plus(mrb, a, b);
170+
*
171+
* // Prints new Concatnated Ruby string.
172+
* mrb_p(mrb, c);
173+
*
174+
* mrb_close(mrb);
175+
* return 0;
176+
* }
177+
*
178+
*
179+
* Result:
180+
*
181+
* => "abc" # First string
182+
* => "def" # Second string
183+
* => "abcdef" # First & Second concatnated.
184+
*
185+
* @param [mrb_state] mrb The current mruby state.
186+
* @param [mrb_value] a First string to concatenate.
187+
* @param [mrb_value] b Second string to concatenate.
188+
* @return [mrb_value] Returns a new String containing a concatenated to b.
95189
*/
96190
MRB_API mrb_value mrb_str_plus(mrb_state*, mrb_value, mrb_value);
97191

98192
/*
99193
* Converts pointer into a Ruby string.
194+
*
195+
* @param [mrb_state] mrb The current mruby state.
196+
* @param [void*] p The pointer to convert to Ruby string.
197+
* @return [mrb_value] Returns a new Ruby String.
100198
*/
101199
MRB_API mrb_value mrb_ptr_to_str(mrb_state *, void*);
102200

103201
/*
104202
* Returns an object as a Ruby string.
203+
*
204+
* @param [mrb_state] mrb The current mruby state.
205+
* @param [mrb_value] obj An object to return as a Ruby string.
206+
* @return [mrb_value] An object as a Ruby string.
105207
*/
106208
MRB_API mrb_value mrb_obj_as_string(mrb_state *mrb, mrb_value obj);
107209

108210
/*
109-
* Resizes the string's length.
211+
* Resizes the string's length. Returns the amount of characters
212+
* in the specified by len.
213+
*
214+
* Example:
215+
*
216+
* !!!c
217+
* int
218+
* main(int argc,
219+
* char **argv)
220+
* {
221+
* // Variable declaration.
222+
* mrb_value str;
223+
*
224+
* mrb_state *mrb = mrb_open();
225+
* if (!mrb)
226+
* {
227+
* // handle error
228+
* }
229+
* // Creates a new string.
230+
* str = mrb_str_new_cstr(mrb, "Hello, world!");
231+
* // Returns 5 characters of
232+
* mrb_str_resize(mrb, str, 5);
233+
* mrb_p(mrb, str);
234+
*
235+
* mrb_close(mrb);
236+
* return 0;
237+
* }
238+
*
239+
* Result:
240+
*
241+
* => "Hello"
242+
*
243+
* @param [mrb_state] mrb The current mruby state.
244+
* @param [mrb_value] str The Ruby string to resize.
245+
* @param [mrb_value] len The length.
246+
* @return [mrb_value] An object as a Ruby string.
110247
*/
111248
MRB_API mrb_value mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len);
112249

113250
/*
114251
* Returns a sub string.
252+
*
253+
* Example:
254+
*
255+
* !!!c
256+
* int
257+
* main(int argc,
258+
* char const **argv)
259+
* {
260+
* // Variable declarations.
261+
* mrb_value str1;
262+
* mrb_value str2;
263+
*
264+
* mrb_state *mrb = mrb_open();
265+
* if (!mrb)
266+
* {
267+
* // handle error
268+
* }
269+
* // Creates new string.
270+
* str1 = mrb_str_new_cstr(mrb, "Hello, world!");
271+
* // Returns a sub-string within the range of 0..2
272+
* str2 = mrb_str_substr(mrb, str1, 0, 2);
273+
*
274+
* // Prints sub-string.
275+
* mrb_p(mrb, str2);
276+
*
277+
* mrb_close(mrb);
278+
* return 0;
279+
* }
280+
*
281+
* Result:
282+
*
283+
* => "He"
284+
*
285+
* @param [mrb_state] mrb The current mruby state.
286+
* @param [mrb_value] str Ruby string.
287+
* @param [mrb_int] beg The beginning point of the sub-string.
288+
* @param [mrb_int] len The end point of the sub-string.
289+
* @return [mrb_value] An object as a Ruby sub-string.
115290
*/
116291
MRB_API mrb_value mrb_str_substr(mrb_state *mrb, mrb_value str, mrb_int beg, mrb_int len);
117292

118293
/*
119294
* Returns a Ruby string type.
295+
*
296+
*
297+
* @param [mrb_state] mrb The current mruby state.
298+
* @param [mrb_value] str Ruby string.
299+
* @return [mrb_value] A Ruby string.
120300
*/
121301
MRB_API mrb_value mrb_string_type(mrb_state *mrb, mrb_value str);
122302

@@ -125,15 +305,32 @@ MRB_API mrb_value mrb_str_buf_new(mrb_state *mrb, size_t capa);
125305

126306
MRB_API const char *mrb_string_value_cstr(mrb_state *mrb, mrb_value *ptr);
127307
MRB_API const char *mrb_string_value_ptr(mrb_state *mrb, mrb_value str);
308+
/*
309+
* Returns the length of the Ruby string.
310+
*
311+
*
312+
* @param [mrb_state] mrb The current mruby state.
313+
* @param [mrb_value] str Ruby string.
314+
* @return [mrb_int] The length of the passed in Ruby string.
315+
*/
128316
MRB_API mrb_int mrb_string_value_len(mrb_state *mrb, mrb_value str);
129317

130318
/*
131319
* Duplicates a string object.
320+
*
321+
*
322+
* @param [mrb_state] mrb The current mruby state.
323+
* @param [mrb_value] str Ruby string.
324+
* @return [mrb_value] Duplicated Ruby string.
132325
*/
133326
MRB_API mrb_value mrb_str_dup(mrb_state *mrb, mrb_value str);
134327

135328
/*
136-
* Returns a symbol from a passed in string.
329+
* Returns a symbol from a passed in Ruby string.
330+
*
331+
* @param [mrb_state] mrb The current mruby state.
332+
* @param [mrb_value] self Ruby string.
333+
* @return [mrb_value] A symbol.
137334
*/
138335
MRB_API mrb_value mrb_str_intern(mrb_state *mrb, mrb_value self);
139336

@@ -147,19 +344,33 @@ MRB_API mrb_value mrb_str_to_str(mrb_state *mrb, mrb_value str);
147344

148345
/*
149346
* Returns true if the strings match and false if the strings don't match.
347+
*
348+
* @param [mrb_state] mrb The current mruby state.
349+
* @param [mrb_value] str1 Ruby string to compare.
350+
* @param [mrb_value] str2 Ruby string to compare.
351+
* @return [mrb_value] boolean value.
150352
*/
151353
MRB_API mrb_bool mrb_str_equal(mrb_state *mrb, mrb_value str1, mrb_value str2);
152354

153355
/*
154356
* Returns a concated string comprised of a Ruby string and a C string.
155357
*
358+
* @param [mrb_state] mrb The current mruby state.
359+
* @param [mrb_value] str Ruby string.
360+
* @param [const char *] ptr A C string.
361+
* @param [size_t] len length of C string.
362+
* @return [mrb_value] A Ruby string.
156363
* @see mrb_str_cat_cstr
157364
*/
158365
MRB_API mrb_value mrb_str_cat(mrb_state *mrb, mrb_value str, const char *ptr, size_t len);
159366

160367
/*
161368
* Returns a concated string comprised of a Ruby string and a C string.
162369
*
370+
* @param [mrb_state] mrb The current mruby state.
371+
* @param [mrb_value] str Ruby string.
372+
* @param [const char *] ptr A C string.
373+
* @return [mrb_value] A Ruby string.
163374
* @see mrb_str_cat
164375
*/
165376
MRB_API mrb_value mrb_str_cat_cstr(mrb_state *mrb, mrb_value str, const char *ptr);

0 commit comments

Comments
 (0)