Man case pattern
From LSWiki
(diff) ←Older revision | Current revision | Newer revision→ (diff)
Contents |
Files
/def/descriptor/case_pattern.c /lib/descriptors/case_pattern.h
Description
Case pattern descriptors implement a mechanism that allows you to abstract the pattern of upper and lower case letters from a string, manipulate it in lower-case, and then restore the original case pattern when you are done. The way this usually goes is like so:
#include <case_pattern.h>
string text = get_some_text(); descriptor pat = Case_Pattern_Extract(&text); text = transform_the_text_in_various_ways(text); text = Case_Pattern_Restore(text, pat);
Note that the argument to Case_Pattern_Extract() is being passed by reference. This causes it to be converted to lower-case. You do not have to pass the argument by reference if you do not want it to be converted to lower-case.
This is usually all you need to know about the mechanism; the fields of the descriptor and so forth are all managed internally. The remainder of this document is provided for reference purposes.
Public Fields
Case_Pattern_Type: The type of the case pattern. This is one of the following:
Case_Pattern_Type_Indeterminate: No representable case pattern was found in the original text. This generally means the original text contained no letters.
Case_Pattern_Type_All_Upper: All letters in the original text were upper-case.
Case_Pattern_Type_All_Lower: All letters in the original text were lower-case.
Case_Pattern_Type_First_Upper: The first letter in the original text was upper-case and the remainder were lower-case.
Case_Pattern_Type_First_Lower: The first letter in the original text was lower-case and the remainder were upper-case.
Case_Pattern_Type_Words_Upper: The original text had a capital letter at the beginning of each word, as if it were the output of the call capitalize_words(some_text).
Case_Pattern_Type_Main_Words_Upper: The original text had a capital letter at the beginning of each word, as if it were the output of the call capitalize_words(some_text, True).
Case_Pattern_Type_Complex: The original text had a complex case pattern, as specified in the Case_Pattern_Content field.
Case_Pattern_Original: The original text the case pattern is based on.
Case_Pattern_Altered: The text with the case pattern extracted (converted to lower-case).
Case_Pattern_Content: For Case_Pattern_Type_Complex patterns, an array describing the case pattern in the original text. Each element will be either Case_Pattern_Element_Upper, Case_Pattern_Element_Lower, or Case_Pattern_Neither, corresponding to one letter in the original text.
Internal Fields
Case_Pattern_Tag: The tag value for the descriptor system.
Support Functions
descriptor Case_Pattern_Extract(string text)
Extracts the case pattern from the specified text and returns it. If the text is passed by reference, it will be converted to lower-case.
string Case_Pattern_Restore(string text, descriptor dxr)
Coerces the specified text into the case pattern described by the descriptor passed and returns the result.
See Also
lower_case(efun), upper_case(efun), capitalize(efun), capitalize_words(sefun), descriptors(mechanisms)