PageSourceSearch

https://www.gites-de-france-morbihan.com/lib_2/js/foncs/string.js?t=1741711295

js gites-de-france-morbihan.com collected 2026-09-30 09:22:40 UTC 6,184 bytes, 177 lines download raw bytes

1// Adrien 10/05/23 : Attention, ce fichier n'est plus utilisé sur la majorité des sites web excepté sur le compte client et le script de résa
2
3function trim(str, chars) {
4    return ltrim(rtrim(str, chars), chars);
5}
6
7function ltrim(str, chars) {
8    chars = chars || "\\s";
9    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
10}
11
12function rtrim(str, chars) {
13    chars = chars || "\\s";
14    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
15}
16
17function str_replace(haystack, needle, replacement) {
18    var temp = haystack.split(needle);
19    return temp.join(replacement);
20}
21
22function str_replace_reg(haystack, needle, replacement) {
23    var r = new RegExp(needle, 'g');
24    return haystack.replace(r, replacement);
25}
26
27sprintfWrapper = {
28	init : function () { 
29		
30		if (typeof arguments == "undefined") { return null; } 
31		if (arguments.length < 1) { return null; } 
32		if (typeof arguments[0] != "string") { return null; } 
33		if (typeof RegExp == "undefined") { return null; } 
34		
35		var string = arguments[0]; 
36		var exp = new RegExp(/(%([%]|(\-)?(\+|\x20)?(0)?(\d+)?(\.(\d)?)?([bcdfosxX])))/g); 
37		var matches = new Array(); 
38		var strings = new Array(); 
39		var convCount = 0; 
40		var stringPosStart = 0; 
41		var stringPosEnd = 0; 
42		var matchPosEnd = 0; 
43		var newString = ''; 
44		var match = null; 
45		
46		while (match = exp.exec(string)) { 
47			if (match[9]) { convCount += 1; } 
48			stringPosStart = matchPosEnd; 
49			stringPosEnd = exp.lastIndex - match[0].length; 
50			strings[strings.length] = string.substring(stringPosStart, stringPosEnd); 
51			matchPosEnd = exp.lastIndex; 
52			matches[matches.length] = { 
53				match: match[0], left: match[3] ? true : false, sign: match[4] || '', pad: match[5] || ' ', min: match[6] || 0, precision: match[8], code: match[9] || '%', negative: parseInt(arguments[convCount]) < 0 ? true : false, argument: String(arguments[convCount]) 
54			}; 
55		} 
56		strings[strings.length] = string.substring(matchPosEnd); 
57		if (matches.length == 0) { return string; } 
58		if ((arguments.length - 1) < convCount) { return null; } 
59		
60		var code = null; 
61		var match = null; 
62		var i = null; 
63		for (i=0; i<matches.length; i++) { 
64			if (matches[i].code == '%') { substitution = '%' } 
65			else if (matches[i].code == 'b') { 
66				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(2)); 
67				substitution = sprintfWrapper.convert(matches[i], true); 
68			}else if (matches[i].code == 'c') { 
69				matches[i].argument = String(String.fromCharCode(parseInt(Math.abs(parseInt(matches[i].argument))))); 
70				substitution = sprintfWrapper.convert(matches[i], true); 
71			}else if (matches[i].code == 'd') { 
72				matches[i].argument = String(Math.abs(Math.floor(parseFloat(matches[i].argument)))); 
73				substitution = sprintfWrapper.convert(matches[i]);
74			}else if (matches[i].code == 'f') { 
75				matches[i].argument = String(Math.abs(parseFloat(matches[i].argument)).toFixed(matches[i].precision ? matches[i].precision : 6)); 
76				substitution = sprintfWrapper.convert(matches[i]); 
77			} else if (matches[i].code == 'o') { 
78				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(8)); 
79				substitution = sprintfWrapper.convert(matches[i]); 
80			} else if (matches[i].code == 's') { 
81				matches[i].argument = matches[i].argument.substring(0, matches[i].precision ? matches[i].precision : matches[i].argument.length); 
82				substitution = sprintfWrapper.convert(matches[i], true); 
83			} else if (matches[i].code == 'x') { 
84				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16)); 
85				substitution = sprintfWrapper.convert(matches[i]); 
86			} else if (matches[i].code == 'X') { 
87				matches[i].argument = String(Math.abs(parseInt(matches[i].argument)).toString(16)); 
88				substitution = sprintfWrapper.convert(matches[i]).toUpperCase(); 
89			} else { substitution = matches[i].match; } 
90			
91			newString += strings[i]; 
92			newString += substitution;
93		} 
94		
95		newString += strings[i]; 
96		return newString; 
97	}, 
98	
99	convert : function(match, nosign){ 
100	
101		if (nosign) { match.sign = ''; } 
102		else { match.sign = match.negative ? '-' : match.sign; } 
103		
104		var l = match.min - match.argument.length + 1 - match.sign.length; 
105		var pad = new Array(l < 0 ? 0 : l).join(match.pad); 
106		if (!match.left) { 
107			if (match.pad == "0" || nosign) { return match.sign + pad + match.argument; } 
108			else { return pad + match.sign + match.argument; } 
109		} 
110		else { 
111			if (match.pad == "0" || nosign) { 
112				return match.sign + match.argument + pad.replace(/0/g, ' '); 
113			}else{
114				return match.sign + match.argument + pad; 
115			} 
116		} 
117	} 
118}
119sprintf = sprintfWrapper.init;
120
121function pad(str, len, pad, dir) {
122
123	var STR_PAD_LEFT = 1;
124	var STR_PAD_RIGHT = 2;
125	var STR_PAD_BOTH = 3;
126
127    if (typeof(len) == "undefined") { var len = 0; }
128    if (typeof(pad) == "undefined") { var pad = ' '; }
129    if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }
130
131    if (len + 1 >= str.length) {
132
133        switch (dir){
134
135            case STR_PAD_LEFT:
136                str = Array(len + 1 - str.length).join(pad) + str;
137            break;
138
139            case STR_PAD_BOTH:
140                var right = Math.ceil((padlen = len - str.length) / 2);
141                var left = padlen - right;
142                str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
143            break;
144
145            default:
146                str = str + Array(len + 1 - str.length).join(pad);
147            break;
148
149        }
150
151    }
152
153    return str;
154
155}
156
157function traiteRetourChariot(chaine, remplacement){
158	return str_replace(new String(chaine), "\n", remplacement); 
159}
160
161function enleveDomaineCurr(chaine) {
162    var loc = new String(document.location);
163    var tabPart = loc.split('/');
164    var httpHost = tabPart[2];
165    var domaine = document.location.protocol + '//' + httpHost;
166    return str_replace(chaine, domaine, '');
167}
168
169function traiteTexteAvantReqAjax(chaine){
170    chaine = chaine.replace(/€/g, 'euros');
171    chaine = encodeURIComponent(chaine);
172	return chaine;
173}
174
175function getPatternUrlValide(){
176    return '/^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/=]*)$/';
177}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.