aimx/info_library/
text_cards.rs

1//! Text function documentation cards.
2//!
3//! Provides comprehensive FunctionCard instances for all 22 text manipulation
4//! functions in the Aim standard library, including detailed usage examples
5//! and cross-references between related functions.
6
7use super::function_card::{ArgumentInfo, FunctionCard};
8
9/// All text function documentation cards.
10pub const TEXT_CARDS: &[FunctionCard] = &[
11    // concat(array) -> Arc<str>
12    FunctionCard {
13        identifier: "concat",
14        signature: "concat(array)",
15        brief: "Concatenate all strings in an array without any separator.",
16        description: "Joins all string elements in the input array into a single string. \
17                     This function is useful when you need to combine multiple text \
18                     fragments without adding any separators between them. For joining \
19                     with separators, use join_with or join functions instead.",
20        arguments: &[
21            &ArgumentInfo {
22                label: "array",
23                description: "Array of strings to concatenate",
24                type_hint: "Array<Arc<str>>",
25                optional: false,
26            },
27        ],
28        returns: "Concatenated string (Arc<str>)",
29        errors: "None - always succeeds with any array of strings",
30        categories: &["text", "collection"],
31        examples: &[
32            r#"concat(("hello", " ", "world")) => "hello world""#,
33            r#"concat(("A", "B", "C")) => "ABC""#,
34            r#"concat(()) => ""#,
35        ],
36    },
37    
38    // join_with(array, sep) -> Arc<str>
39    FunctionCard {
40        identifier: "join_with",
41        signature: "join_with(array, separator)",
42        brief: "Join strings in an array with a specified separator.",
43        description: "Combines all strings in the input array, inserting the specified \
44                     separator between each element. This is the inverse operation of \
45                     split and is useful for creating comma-separated lists, pipe-delimited \
46                     strings, or any other custom delimiter format.",
47        arguments: &[
48            &ArgumentInfo {
49                label: "array",
50                description: "Array of strings to join",
51                type_hint: "Array<Arc<str>>",
52                optional: false,
53            },
54            &ArgumentInfo {
55                label: "separator",
56                description: "String to insert between each element",
57                type_hint: "Arc<str>",
58                optional: false,
59            },
60        ],
61        returns: "Joined string with separators (Arc<str>)",
62        errors: "None - always succeeds with any array and separator",
63        categories: &["text", "collection"],
64        examples: &[
65            r#"join_with(("a", "b", "c"), ", ") => "a, b, c""#,
66            r#"join_with(("2024", "01", "15"), "-") => "2024-01-15""#,
67            r#"join_with(("hello", "world"), "") => "helloworld""#,
68        ],
69    },
70    
71    // split(text, delim) -> Vec<Arc<str>>
72    FunctionCard {
73        identifier: "split",
74        signature: "split(text, delimiter)",
75        brief: "Split text into an array using the specified delimiter.",
76        description: "Divides a string into multiple substrings based on the delimiter \
77                     provided. This is the inverse operation of join_with and is commonly \
78                     used for parsing CSV data, extracting parts of file paths, or breaking \
79                     down structured text formats.",
80        arguments: &[
81            &ArgumentInfo {
82                label: "text",
83                description: "String to split into parts",
84                type_hint: "Arc<str>",
85                optional: false,
86            },
87            &ArgumentInfo {
88                label: "delimiter",
89                description: "String pattern to split on",
90                type_hint: "Arc<str>",
91                optional: false,
92            },
93        ],
94        returns: "Array of substrings (Vec<Arc<str>>)",
95        errors: "None - always succeeds, returns original text if delimiter not found",
96        categories: &["text", "collection"],
97        examples: &[
98            r#"split("a,b,c", ",") => ("a", "b", "c")"#,
99            r#"split("path/to/file", "/") => ("path", "to", "file")"#,
100            r#"split("hello", "x") => ("hello",)"#,
101        ],
102    },
103    
104    // substring(text, start, len) -> Arc<str>
105    FunctionCard {
106        identifier: "substring",
107        signature: "substring(text, start, length)",
108        brief: "Extract a portion of text starting at a byte index with specified length.",
109        description: "Returns a substring starting from the specified byte position and \
110                     extending for the given number of bytes. If the start position is \
111                     beyond the text length, returns an empty string. If the length would \
112                     exceed the text bounds, truncates to the end of the string.",
113        arguments: &[
114            &ArgumentInfo {
115                label: "text",
116                description: "Source string to extract from",
117                type_hint: "Arc<str>",
118                optional: false,
119            },
120            &ArgumentInfo {
121                label: "start",
122                description: "Byte index to start extraction (0-based)",
123                type_hint: "f64",
124                optional: false,
125            },
126            &ArgumentInfo {
127                label: "length",
128                description: "Number of bytes to extract",
129                type_hint: "f64",
130                optional: false,
131            },
132        ],
133        returns: "Extracted substring (Arc<str>)",
134        errors: "Returns empty string if start >= text length",
135        categories: &["text"],
136        examples: &[
137            r#"substring("hello world", 0, 5) => "hello""#,
138            r#"substring("hello world", 6, 5) => "world""#,
139            r#"substring("hello", 10, 5) => ""#,
140        ],
141    },
142    
143    // upper(text) -> Arc<str>
144    FunctionCard {
145        identifier: "upper",
146        signature: "upper(text)",
147        brief: "Convert all characters to uppercase.",
148        description: "Transforms all alphabetic characters in the input string to their \
149                     uppercase equivalents. Non-alphabetic characters (numbers, symbols, \
150                     whitespace) remain unchanged. This function is useful for case-insensitive \
151                     comparisons or formatting text for display.",
152        arguments: &[
153            &ArgumentInfo {
154                label: "text",
155                description: "String to convert to uppercase",
156                type_hint: "Arc<str>",
157                optional: false,
158            },
159        ],
160        returns: "Uppercase string (Arc<str>)",
161        errors: "None - always succeeds",
162        categories: &["text"],
163        examples: &[
164            r#"upper("hello world") => "HELLO WORLD""#,
165            r#"upper("ABC123") => "ABC123""#,
166            r#"upper("") => ""#,
167        ],
168    },
169    
170    // lower(text) -> Arc<str>
171    FunctionCard {
172        identifier: "lower",
173        signature: "lower(text)",
174        brief: "Convert all characters to lowercase.",
175        description: "Transforms all alphabetic characters in the input string to their \
176                     lowercase equivalents. Non-alphabetic characters remain unchanged. \
177                     This function is commonly used for normalizing text input or preparing \
178                     data for case-insensitive operations.",
179        arguments: &[
180            &ArgumentInfo {
181                label: "text",
182                description: "String to convert to lowercase",
183                type_hint: "Arc<str>",
184                optional: false,
185            },
186        ],
187        returns: "Lowercase string (Arc<str>)",
188        errors: "None - always succeeds",
189        categories: &["text"],
190        examples: &[
191            r#"lower("HELLO WORLD") => "hello world""#,
192            r#"lower("ABC123") => "abc123""#,
193            r#"lower("") => ""#,
194        ],
195    },
196    
197    // proper(text) -> Arc<str>
198    FunctionCard {
199        identifier: "proper",
200        signature: "proper(text)",
201        brief: "Convert text to title/proper case with first letter of each word capitalized.",
202        description: "Transforms the input string so that the first alphabetic character \
203                     of each word is uppercase and all other alphabetic characters are \
204                     lowercase. Words are separated by non-alphabetic characters. This \
205                     function is useful for formatting names, titles, and headings.",
206        arguments: &[
207            &ArgumentInfo {
208                label: "text",
209                description: "String to convert to proper case",
210                type_hint: "Arc<str>",
211                optional: false,
212            },
213        ],
214        returns: "Proper case string (Arc<str>)",
215        errors: "None - always succeeds",
216        categories: &["text"],
217        examples: &[
218            r#"proper("hello world") => "Hello World""#,
219            r#"proper("john doe") => "John Doe""#,
220            r#"proper("ABC DEF") => "Abc Def""#,
221        ],
222    },
223    
224    // trim(text) -> Arc<str>
225    FunctionCard {
226        identifier: "trim",
227        signature: "trim(text)",
228        brief: "Remove leading and trailing whitespace from text.",
229        description: "Strips all whitespace characters (spaces, tabs, newlines) from the \
230                     beginning and end of the input string. This function is essential \
231                     for cleaning up user input, removing extra spaces from concatenated \
232                     strings, or normalizing text before comparisons.",
233        arguments: &[
234            &ArgumentInfo {
235                label: "text",
236                description: "String to trim whitespace from",
237                type_hint: "Arc<str>",
238                optional: false,
239            },
240        ],
241        returns: "Trimmed string (Arc<str>)",
242        errors: "None - always succeeds",
243        categories: &["text"],
244        examples: &[
245            r#"trim("  hello world  ") => "hello world""#,
246            r#"trim("\t\n  text  \r\n") => "text""#,
247            r#"trim("") => ""#,
248        ],
249    },
250    
251    // contains(text, substr) -> bool
252    FunctionCard {
253        identifier: "contains",
254        signature: "contains(text, substring)",
255        brief: "Check if text contains a specified substring.",
256        description: "Performs a case-sensitive search to determine if the specified \
257                     substring exists anywhere within the input text. Returns true if \
258                     found, false otherwise. This function is commonly used for filtering \
259                     data, validating input, or conditional logic based on text content.",
260        arguments: &[
261            &ArgumentInfo {
262                label: "text",
263                description: "String to search within",
264                type_hint: "Arc<str>",
265                optional: false,
266            },
267            &ArgumentInfo {
268                label: "substring",
269                description: "Substring to search for",
270                type_hint: "Arc<str>",
271                optional: false,
272            },
273        ],
274        returns: "Boolean indicating if substring is found (bool)",
275        errors: "None - always succeeds",
276        categories: &["text", "logical"],
277        examples: &[
278            r#"contains("hello world", "world") => true"#,
279            r#"contains("hello world", "earth") => false"#,
280            r#"contains("", "test") => false"#,
281        ],
282    },
283    
284    // replace(text, from, to) -> Arc<str>
285    FunctionCard {
286        identifier: "replace",
287        signature: "replace(text, old, new)",
288        brief: "Replace the first occurrence of a substring with a new string.",
289        description: "Searches for the first instance of the specified substring and \
290                     replaces it with the replacement string. Only the first occurrence \
291                     is replaced; subsequent occurrences remain unchanged. For replacing \
292                     all occurrences, use the replace_all function instead.",
293        arguments: &[
294            &ArgumentInfo {
295                label: "text",
296                description: "String to perform replacement on",
297                type_hint: "Arc<str>",
298                optional: false,
299            },
300            &ArgumentInfo {
301                label: "old",
302                description: "Substring to replace",
303                type_hint: "Arc<str>",
304                optional: false,
305            },
306            &ArgumentInfo {
307                label: "new",
308                description: "String to replace the old substring",
309                type_hint: "Arc<str>",
310                optional: false,
311            },
312        ],
313        returns: "String with first occurrence replaced (Arc<str>)",
314        errors: "None - always succeeds",
315        categories: &["text"],
316        examples: &[
317            r#"replace("hello world", "world", "universe") => "hello universe""#,
318            r#"replace("a-b-c", "-", "_") => "a_b-c""#,
319            r#"replace("no change", "xyz", "abc") => "no change""#,
320        ],
321    },
322    
323    // replace_all(text, from, to) -> Arc<str>
324    FunctionCard {
325        identifier: "replace_all",
326        signature: "replace_all(text, old, new)",
327        brief: "Replace all occurrences of a substring with a new string.",
328        description: "Searches through the entire input string and replaces every \
329                     instance of the specified substring with the replacement string. \
330                     This function is useful for cleaning up data, removing unwanted \
331                     characters, or performing bulk text transformations.",
332        arguments: &[
333            &ArgumentInfo {
334                label: "text",
335                description: "String to perform replacement on",
336                type_hint: "Arc<str>",
337                optional: false,
338            },
339            &ArgumentInfo {
340                label: "old",
341                description: "Substring to replace",
342                type_hint: "Arc<str>",
343                optional: false,
344            },
345            &ArgumentInfo {
346                label: "new",
347                description: "String to replace the old substring",
348                type_hint: "Arc<str>",
349                optional: false,
350            },
351        ],
352        returns: "String with all occurrences replaced (Arc<str>)",
353        errors: "None - always succeeds",
354        categories: &["text"],
355        examples: &[
356            r#"replace_all("a-b-c", "-", "_") => "a_b_c""#,
357            r#"replace_all("hello world", "l", "x") => "hexxo worxd""#,
358            r#"replace_all("no change", "xyz", "abc") => "no change""#,
359        ],
360    },
361    
362    // starts_with(text, prefix) -> bool
363    FunctionCard {
364        identifier: "starts_with",
365        signature: "starts_with(text, prefix)",
366        brief: "Check if text begins with a specified prefix.",
367        description: "Performs a case-sensitive check to determine if the input string \
368                     starts with the specified prefix. Returns true if the text begins \
369                     with the prefix, false otherwise. This function is useful for \
370                     filtering data, validating file extensions, or checking URL protocols.",
371        arguments: &[
372            &ArgumentInfo {
373                label: "text",
374                description: "String to check prefix of",
375                type_hint: "Arc<str>",
376                optional: false,
377            },
378            &ArgumentInfo {
379                label: "prefix",
380                description: "Prefix string to check for",
381                type_hint: "Arc<str>",
382                optional: false,
383            },
384        ],
385        returns: "Boolean indicating if text starts with prefix (bool)",
386        errors: "None - always succeeds",
387        categories: &["text", "logical"],
388        examples: &[
389            r#"starts_with("hello world", "hello") => true"#,
390            r#"starts_with("hello world", "world") => false"#,
391            r#"starts_with("", "test") => false"#,
392        ],
393    },
394    
395    // ends_with(text, suffix) -> bool
396    FunctionCard {
397        identifier: "ends_with",
398        signature: "ends_with(text, suffix)",
399        brief: "Check if text ends with a specified suffix.",
400        description: "Performs a case-sensitive check to determine if the input string \
401                     ends with the specified suffix. Returns true if the text ends with \
402                     the suffix, false otherwise. This function is commonly used for \
403                     validating file extensions, checking URL paths, or filtering data.",
404        arguments: &[
405            &ArgumentInfo {
406                label: "text",
407                description: "String to check suffix of",
408                type_hint: "Arc<str>",
409                optional: false,
410            },
411            &ArgumentInfo {
412                label: "suffix",
413                description: "Suffix string to check for",
414                type_hint: "Arc<str>",
415                optional: false,
416            },
417        ],
418        returns: "Boolean indicating if text ends with suffix (bool)",
419        errors: "None - always succeeds",
420        categories: &["text", "logical"],
421        examples: &[
422            r#"ends_with("hello world", "world") => true"#,
423            r#"ends_with("hello world", "hello") => false"#,
424            r#"ends_with("", "test") => false"#,
425        ],
426    },
427    
428    // if_empty(text, default) -> Arc<str>
429    FunctionCard {
430        identifier: "if_empty",
431        signature: "if_empty(text, default)",
432        brief: "Return default value if text is empty or contains only whitespace.",
433        description: "Checks if the input string is empty or contains only whitespace \
434                     characters. If so, returns the specified default value. Otherwise, \
435                     returns the original text. This function is useful for providing \
436                     fallback values for optional text fields or cleaning up user input.",
437        arguments: &[
438            &ArgumentInfo {
439                label: "text",
440                description: "String to check for emptiness",
441                type_hint: "Arc<str>",
442                optional: false,
443            },
444            &ArgumentInfo {
445                label: "default",
446                description: "Value to return if text is empty",
447                type_hint: "Arc<str>",
448                optional: false,
449            },
450        ],
451        returns: "Original text or default value (Arc<str>)",
452        errors: "None - always succeeds",
453        categories: &["text", "logical"],
454        examples: &[
455            r#"if_empty("", "default") => "default""#,
456            r#"if_empty("   ", "default") => "default""#,
457            r#"if_empty("hello", "default") => "hello""#,
458        ],
459    },
460    
461    // pluralize(text, count, suffix) -> Arc<str>
462    FunctionCard {
463        identifier: "pluralize",
464        signature: "pluralize(text, count, suffix)",
465        brief: "Add suffix to text when count is not equal to 1.",
466        description: "Conditionally appends a suffix to the input text based on the \
467                     count value. If count equals 1, returns the original text. \
468                     Otherwise, appends the specified suffix. This function is useful \
469                     for creating grammatically correct messages with dynamic counts.",
470        arguments: &[
471            &ArgumentInfo {
472                label: "text",
473                description: "Base text to potentially pluralize",
474                type_hint: "Arc<str>",
475                optional: false,
476            },
477            &ArgumentInfo {
478                label: "count",
479                description: "Numeric value to check for pluralization",
480                type_hint: "f64",
481                optional: false,
482            },
483            &ArgumentInfo {
484                label: "suffix",
485                description: "Suffix to append when count != 1",
486                type_hint: "Arc<str>",
487                optional: false,
488            },
489        ],
490        returns: "Text with or without suffix (Arc<str>)",
491        errors: "None - always succeeds",
492        categories: &["text"],
493        examples: &[
494            r#"pluralize("item", 1, "s") => "item""#,
495            r#"pluralize("item", 5, "s") => "items""#,
496            r#"pluralize("child", 2, "ren") => "children""#,
497        ],
498    },
499    
500    // truncate(text, max_len, suffix) -> Arc<str>
501    FunctionCard {
502        identifier: "truncate",
503        signature: "truncate(text, max_length, suffix)",
504        brief: "Limit text to maximum length and append suffix if truncated.",
505        description: "Shortens the input string to the specified maximum length. If the \
506                     text exceeds this length, it is truncated and the specified suffix \
507                     is appended. If the text is already at or below the maximum length, \
508                     it is returned unchanged. This function is useful for creating \
509                     summaries, fitting text into limited spaces, or generating previews.",
510        arguments: &[
511            &ArgumentInfo {
512                label: "text",
513                description: "String to potentially truncate",
514                type_hint: "Arc<str>",
515                optional: false,
516            },
517            &ArgumentInfo {
518                label: "max_length",
519                description: "Maximum number of characters to keep",
520                type_hint: "f64",
521                optional: false,
522            },
523            &ArgumentInfo {
524                label: "suffix",
525                description: "String to append when text is truncated",
526                type_hint: "Arc<str>",
527                optional: false,
528            },
529        ],
530        returns: "Truncated text with optional suffix (Arc<str>)",
531        errors: "None - always succeeds",
532        categories: &["text"],
533        examples: &[
534            r#"truncate("hello world", 5, "...") => "hello...""#,
535            r#"truncate("short", 10, "...") => "short""#,
536            r#"truncate("very long text", 8, "...") => "very lon...""#,
537        ],
538    },
539    
540    // join(array) -> Arc<str>
541    FunctionCard {
542        identifier: "join",
543        signature: "join(array)",
544        brief: "Join array elements with newline characters.",
545        description: "Combines all strings in the input array into a single string, \
546                     separating each element with a newline character. This function \
547                     is useful for creating multi-line text from arrays, formatting \
548                     lists for display, or preparing data for text-based output.",
549        arguments: &[
550            &ArgumentInfo {
551                label: "array",
552                description: "Array of strings to join with newlines",
553                type_hint: "Array<Arc<str>>",
554                optional: false,
555            },
556        ],
557        returns: "Joined string with newlines (Arc<str>)",
558        errors: "None - always succeeds",
559        categories: &["text", "collection"],
560        examples: &[
561            r#"join(("line1", "line2", "line3")) => "line1\nline2\nline3""#,
562            r#"join(("single")) => "single""#,
563            r#"join(()) => ""#,
564        ],
565    },
566    
567    // bullet_list(array) -> Arc<str>
568    FunctionCard {
569        identifier: "bullet_list",
570        signature: "bullet_list(array)",
571        brief: "Create a bulleted list with dash prefixes.",
572        description: "Transforms an array of strings into a formatted bulleted list, \
573                     with each element prefixed by a dash (-) and separated by newlines. \
574                     This function is useful for creating readable lists, formatting \
575                     reports, or displaying structured information in a clear format.",
576        arguments: &[
577            &ArgumentInfo {
578                label: "array",
579                description: "Array of strings to format as bullet points",
580                type_hint: "Array<Arc<str>>",
581                optional: false,
582            },
583        ],
584        returns: "Formatted bulleted list (Arc<str>)",
585        errors: "None - always succeeds",
586        categories: &["text", "collection"],
587        examples: &[
588            r#"bullet_list(("item1", "item2", "item3")) => "- item1\n- item2\n- item3""#,
589            r#"bullet_list(("single item")) => "- single item""#,
590            r#"bullet_list(()) => ""#,
591        ],
592    },
593    
594    // numbered_list(array) -> Arc<str>
595    FunctionCard {
596        identifier: "numbered_list",
597        signature: "numbered_list(array)",
598        brief: "Create a numbered list starting from 1.",
599        description: "Transforms an array of strings into a formatted numbered list, \
600                     with each element prefixed by its position number and separated \
601                     by newlines. The numbering starts from 1. This function is useful \
602                     for creating ordered lists, step-by-step instructions, or any \
603                     content requiring sequential numbering.",
604        arguments: &[
605            &ArgumentInfo {
606                label: "array",
607                description: "Array of strings to format as numbered items",
608                type_hint: "Array<Arc<str>>",
609                optional: false,
610            },
611        ],
612        returns: "Formatted numbered list (Arc<str>)",
613        errors: "None - always succeeds",
614        categories: &["text", "collection"],
615        examples: &[
616            r#"numbered_list(("first", "second", "third")) => "1. first\n2. second\n3. third""#,
617            r#"numbered_list(("single")) => "1. single""#,
618            r#"numbered_list(()) => ""#,
619        ],
620    },
621    
622    // format_phone(text) -> Arc<str>
623    FunctionCard {
624        identifier: "format_phone",
625        signature: "format_phone(phone)",
626        brief: "Format US phone numbers to (XXX) XXX-XXXX pattern.",
627        description: "Extracts exactly 10 digits from the input string and formats them \
628                     into the standard US phone number pattern: (XXX) XXX-XXXX. If the \
629                     input does not contain exactly 10 digits, returns the original \
630                     text unchanged. This function is useful for normalizing phone \
631                     number input or displaying phone numbers in a consistent format.",
632        arguments: &[
633            &ArgumentInfo {
634                label: "phone",
635                description: "Phone number string to format",
636                type_hint: "Arc<str>",
637                optional: false,
638            },
639        ],
640        returns: "Formatted phone number or original text (Arc<str>)",
641        errors: "None - always succeeds, returns original if not exactly 10 digits",
642        categories: &["text"],
643        examples: &[
644            r#"format_phone("1234567890") => "(123) 456-7890""#,
645            r#"format_phone("(555) 123-4567") => "(555) 123-4567""#,
646            r#"format_phone("123-456-789") => "123-456-789""#,
647        ],
648    },
649    
650    // mask_sensitive(text, keep_start, keep_end) -> Arc<str>
651    FunctionCard {
652        identifier: "mask_sensitive",
653        signature: "mask_sensitive(text, keep_start, keep_end)",
654        brief: "Mask sensitive data by replacing middle characters with asterisks.",
655        description: "Protects sensitive information by replacing characters in the middle \
656                     of the input string with asterisks (*). The number of characters to \
657                     preserve at the start and end is configurable. This function is \
658                     useful for displaying credit card numbers, passwords, or other \
659                     sensitive data while maintaining some visibility for identification.",
660        arguments: &[
661            &ArgumentInfo {
662                label: "text",
663                description: "Sensitive text to mask",
664                type_hint: "Arc<str>",
665                optional: false,
666            },
667            &ArgumentInfo {
668                label: "keep_start",
669                description: "Number of characters to keep at the start",
670                type_hint: "f64",
671                optional: false,
672            },
673            &ArgumentInfo {
674                label: "keep_end",
675                description: "Number of characters to keep at the end",
676                type_hint: "f64",
677                optional: false,
678            },
679        ],
680        returns: "Masked text with asterisks (Arc<str>)",
681        errors: "None - always succeeds",
682        categories: &["text"],
683        examples: &[
684            r#"mask_sensitive("1234567890123456", 4, 4) => "1234********3456""#,
685            r#"mask_sensitive("password123", 2, 2) => "pa*********12""#,
686            r#"mask_sensitive("short", 1, 1) => "s***t""#,
687        ],
688    },
689];