Abbreviate a string using dictionary in C

2018-02-20 04:36:48

Abbreviate a given string using a dictionary of acceptable



Only "whole words" should be abbreviated. That is, if the word

"record" can be abbreviated to "rec", "records" SHOULD NOT be

abbreviated to "recs".

A "whole word" is a sequence of alphanumeric characters.

If the abbreviated string will not fit in the destination buffer clamp the string.

Bonus points for allowing the substitution to be case insensitive, but also case aware. It should handle three cases, the original word

all lower case, all upper case, or the first letter only being

capitalized. Mixed cases can be handled in any reasonable way.

For example, if the dictionary contains: "record"->"rec":

"record" should be replaced with "rec"

"Record" should be replaced with "Rec"

"RECORD" should be replaced with "REC"

"ReCord" can be replaced with "rec", "Rec" or "REC"

@param str - source string to abbreviate (NULL terminated)

@param str_