Code Duplication    Length = 46-49 lines in 2 locations

src/ub.strings.find.index.js 2 locations

@@ 67-115 (lines=49) @@
64
			// FIRST INDEX
65
			
66
			// CASE INSENSITIVE
67
			if (!caseSensitive) {
68
				
69
				// init casing tables
70
				if (UB.UTF_lowerToUpper == null){
71
					UB.initCasing();
72
				}
73
				
74
				
75
				// very fast CI comparison
76
				
77
				// per main char
78
				for (var m = startAt;m <= ml;m++){
79
					
80
					
81
					// per substring char
82
					var match = true;
83
					for (var s = 0;s<sl;s++){
84
						
85
						var c1 = text.charCodeAt(m + s);
86
						var c2 = search.charCodeAt(s);
87
						
88
						// CI
89
						if (c1 <= UB.UTF_casingTablesMax){ /// CI
90
							c1 = UB.UTF_upperToLower[c1];
91
						}
92
						if (!substringIsLower){
93
							if (c2 <= UB.UTF_casingTablesMax){ /// CI
94
								c2 = UB.UTF_upperToLower[c2];
95
							}
96
						}
97
						
98
						if (c1 != c2) {
99
							match = false;
100
							break;
101
						}
102
						
103
					}
104
					
105
					if (match){
106
						return m;
107
					}
108
					
109
				}
110
				
111
				return -1;
112
				
113
				
114
				//return text.toUpperCase().indexOf(search.toUpperCase(), startAt);
115
			}
116
			
117
			// CASE SENSITIVE
118
			return text.indexOf(search, startAt);
@@ 126-171 (lines=46) @@
123
			// LAST INDEX
124
			
125
			// CASE INSENSITIVE
126
			if (!caseSensitive) {
127
				
128
				// init casing tables
129
				if (UB.UTF_lowerToUpper == null){
130
					UB.initCasing();
131
				}
132
				
133
				
134
				// very fast CI comparison
135
				
136
				// per main char
137
				for (var m = startAt;m >= 0;m--){
138
					
139
					
140
					// per substring char
141
					match = true;
142
					for (var s = 0;s<sl;s++){
143
						
144
						c1 = text.charCodeAt(m + s);
145
						c2 = search.charCodeAt(s);
146
						
147
						// CI
148
						if (c1 <= UB.UTF_casingTablesMax){ /// CI
149
							c1 = UB.UTF_upperToLower[c1];
150
						}
151
						if (!substringIsLower){
152
							if (c2 <= UB.UTF_casingTablesMax){ /// CI
153
								c2 = UB.UTF_upperToLower[c2];
154
							}
155
						}
156
						
157
						if (c1 != c2) {
158
							match = false;
159
							break;
160
						}
161
						
162
					}
163
					
164
					if (match){
165
						return m;
166
					}
167
					
168
				}
169
				
170
				return -1;
171
			}
172
			
173
			// CASE SENSITIVE
174
			return text.lastIndexOf(search, startAt);