1 # ===================================================================== 2 # normalizeString: perform basic checks on the received data. 3 # 4 # Copyright (c) 2006 Carlo Strozzi 5 # 6 # This program is free software; you can redistribute it and/or modify 7 # it under the terms of the GNU General Public License as published by 8 # the Free Software Foundation; version 2 dated June, 1991. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 # 19 # ===================================================================== 20 21 # ===================================================================== 22 # string normalizeString(string s, boolean mux) 23 # 24 # If mux is set to '1' then embedded newlines are turned into 25 # continuation lines suitable for the 'muxtotable' NoSQL operator, 26 # otherwise the string is truncated at the first embedded newline. 27 # ===================================================================== 28 29 function normalizeString(s, mux) { 30 31 gsub(/\t/, " ", s); gsub(/' */,"'",s) 32 s = toupper(_strip(s,_O_MIDDLE)) 33 34 # handle italian accents. 35 gsub(/à/,"A`",s) 36 gsub(/[èé]/,"E`",s) 37 gsub(/ì/,"I`",s) 38 gsub(/ò/,"O`",s) 39 gsub(/ù/,"U`",s) 40 41 # strip leading/trailing newlines (may occur in text-areas). 42 sub(/^\n+/,"",s); sub(/\n+$/,"",s) 43 44 # handle middle newlines as appropriate (see 'muxtotable').. 45 if (mux) gsub(/\n/,"\n@",s) 46 else sub(/\n.*/,_NULL,s) 47 48 # Values are to be used with the 'updtable' NoSQL operator, 49 # so I prefer to reject any default delete string. 50 if (s == "..DEL..") s = _NULL 51 52 return s 53 } 54 55 # EOF