MCPcopy Create free account
hub / github.com/NetHack/NetHack / singplur_compound

Function singplur_compound

src/objnam.c:2782–2814  ·  view source on GitHub ↗

searches for common compounds, ex. lump of royal jelly */

Source from the content-addressed store, hash-verified

2780
2781/* searches for common compounds, ex. lump of royal jelly */
2782staticfn char *
2783singplur_compound(char *str)
2784{
2785 /* if new entries are added, be sure to keep compound_start[] in sync */
2786 static const char *const compounds[] =
2787 {
2788 " of ", " labeled ", " called ",
2789 " named ", " above", /* lurkers above */
2790 " versus ", " from ", " in ",
2791 " on ", " a la ", " with", /* " with "? */
2792 " de ", " d'", " du ",
2793 " au ", "-in-", "-at-",
2794 0
2795 }, /* list of first characters for all compounds[] entries */
2796 compound_start[] = " -";
2797
2798 const char *const *cmpd;
2799 char *p;
2800
2801 for (p = str; *p; ++p) {
2802 /* substring starting at p can only match if *p is found
2803 within compound_start[] */
2804 if (!strchr(compound_start, *p))
2805 continue;
2806
2807 /* check current substring against all words in the compound[] list */
2808 for (cmpd = compounds; *cmpd; ++cmpd)
2809 if (!strncmpi(p, *cmpd, (int) strlen(*cmpd)))
2810 return p;
2811 }
2812 /* wasn't recognized as a compound phrase */
2813 return 0;
2814}
2815
2816/* Plural routine; once upon a time it may have been chiefly used for
2817 * user-defined fruits, but it is now used extensively throughout the

Callers 2

makepluralFunction · 0.85
makesingularFunction · 0.85

Calls 1

strncmpiFunction · 0.70

Tested by

no test coverage detected