Advertisement
Guest User

/source/metaphone_ptbr.h

a guest
Mar 16th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. /* ***************************************
  2. Copyright 2008-2017, Carlos Costa Jordao <carlosjordao@gmail.com>.
  3. All rights reserved.
  4.  
  5. Redistribution and use in source and binary forms, with or without modification,
  6. are permitted provided that the following conditions are met:
  7.  
  8. 1. Redistributions of source code must retain the above copyright notice, this
  9. list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice, this
  11. list of conditions and the following disclaimer in the documentation and/or
  12. other materials provided with the distribution.
  13.  
  14.  
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25.  
  26. */
  27.  
  28.  
  29. #ifndef METAPHONE_PTBR_H
  30. #define METAPHONE_PTBR_H
  31.  
  32. #include <ctype.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <assert.h>
  36. #include <wchar.h>
  37. #include <wctype.h>
  38. #include <locale.h>
  39.  
  40. /* 50 should be enough for long names - based on statistical analysis
  41. * but for single words you should use something like 3 or 4 as max length
  42. * for the resultant metaphone string. That would lead you to the best scenario.
  43. */
  44. #define MAX_METAPHONE_LENGTH 4
  45.  
  46. /* this one will help detect, in special inside MakeUpperAndClean() */
  47. #define DOUBLED_CHAR(i) ((*i) == (*(i-1)))
  48. /* Is this character outside of a word? */
  49. #define WORD_EDGE(c) (c == L'\0' || isspace(c) || c==separator)
  50.  
  51.  
  52. /* this typedef was originally in the perl module's .h file */
  53. typedef struct
  54. {
  55. char *str;
  56. int length;
  57. int bufsize;
  58. int free_string_on_destroy;
  59. } metastring;
  60.  
  61.  
  62. metastring * NewMetaString(char *init_str);
  63. void DestroyMetaString(metastring * s);
  64. void IncreaseBuffer(metastring * s, int chars_needed);
  65. wchar_t* MakeUpperAndClean(wchar_t * s);
  66. wchar_t GetAt(wchar_t* s, int pos);
  67. wchar_t GetSimplifiedAt(wchar_t* s, int pos);
  68. void MetaphAdd(metastring * s, char *new_str);
  69. //void MetaphAddChr(metastring * s, char new_str);
  70. void MetaphAddChr(metastring * s, wchar_t new_str);
  71. //int isVowel(char chr);
  72. int isVowel(wchar_t chr);
  73. char * Metaphone_PTBR(const wchar_t *str, const int max_length);
  74. /* word bound char, as demanded. This is good when applied in long names */
  75. char * Metaphone_PTBR_s(const wchar_t *str, const int max_length, const wchar_t separator);
  76.  
  77.  
  78. #endif
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement