@@ 352-391 (lines=40) @@ | ||
349 | } |
|
350 | ||
351 | // ===================textFrom================================= |
|
352 | function textTo (inpObj, cmdArgs, inclusive) { |
|
353 | // cmdArgs is an array of arguments |
|
354 | // inpObj is an object containing the text object we need to snip contents from |
|
355 | // the format of the call is eg. |
|
356 | // '--textTo "some text" 2 - would go up to the second instance of "some text" |
|
357 | if (setInputType(inpObj, 'plain')) { |
|
358 | let occ |
|
359 | if (cmdArgs.length === 1) { |
|
360 | occ = 1 // by default we take from the first occurrence of this text |
|
361 | } else if (cmdArgs.length === 2) { |
|
362 | if ((cmdArgs[1] - 0) === (cmdArgs[1] - 0)) { |
|
363 | occ = (cmdArgs[1] - 0) |
|
364 | if (occ < 1) { |
|
365 | inpObj.error.push('--to and --finish require their second argument to be a numeric values of at least 1 being the instance required') |
|
366 | return |
|
367 | } |
|
368 | } else { |
|
369 | inpObj.error.push("--to and --finish require their second argument to be numeric eg. '--from \"some text\" 2' with the optional second argument being the instance required") |
|
370 | return |
|
371 | } |
|
372 | } else { |
|
373 | inpObj.error.push("--to and --finish require 1 or 2 arguments eg. '--from \"some text\"' with the optional second argument being the instance required.") |
|
374 | return |
|
375 | } |
|
376 | let x = -1 |
|
377 | let arg = removeQuotes(cmdArgs[0]) |
|
378 | for (let i = 0; i < occ; i++) { |
|
379 | x = inpObj.plain.indexOf(arg, x + 1) |
|
380 | } |
|
381 | if (x === -1) { |
|
382 | inpObj.error.push('unable to find occurrence ' + occ + ' of "' + arg + '"') |
|
383 | return |
|
384 | } |
|
385 | if (inclusive === true) { |
|
386 | inpObj.plain = inpObj.plain.substring(0, x + arg.length) |
|
387 | } else { |
|
388 | inpObj.plain = inpObj.plain.substring(0, x) |
|
389 | } |
|
390 | } |
|
391 | } |
|
392 | ||
@@ 310-349 (lines=40) @@ | ||
307 | } |
|
308 | ||
309 | // ===================textFrom================================= |
|
310 | function textFrom (inpObj, cmdArgs, inclusive) { |
|
311 | // cmdArgs is an array of arguments |
|
312 | // inpObj is an object containing the text object we need to snip contents from |
|
313 | // the format of the call is eg. |
|
314 | // '--textFrom "some text" 2 - would start from the second instance of "some text" |
|
315 | if (setInputType(inpObj, 'plain')) { |
|
316 | let occ |
|
317 | if (cmdArgs.length === 1) { |
|
318 | occ = 1 // by default we take from the first occurrence of this text |
|
319 | } else if (cmdArgs.length === 2) { |
|
320 | if ((cmdArgs[1] - 0) === (cmdArgs[1] - 0)) { |
|
321 | occ = (cmdArgs[1] - 0) |
|
322 | if (occ < 1) { |
|
323 | inpObj.error.push('--from and --start require their second argument to be a numeric values of at least 1 being the instance required') |
|
324 | return |
|
325 | } |
|
326 | } else { |
|
327 | inpObj.error.push("--from and --start require their second argument to be numeric eg. '--from \"some text\" 2' with the optional second argument being the instance required") |
|
328 | return |
|
329 | } |
|
330 | } else { |
|
331 | inpObj.error.push("--from and --start require 1 or 2 arguments eg. '--from \"some text\"' with the optional second argument being the instance required.") |
|
332 | return |
|
333 | } |
|
334 | let x = -1 |
|
335 | let arg = removeQuotes(cmdArgs[0]) |
|
336 | for (let i = 0; i < occ; i++) { |
|
337 | x = inpObj.plain.indexOf(arg, x + 1) |
|
338 | } |
|
339 | if (x === -1) { |
|
340 | inpObj.error.push('unable to find occurrence ' + occ + ' of "' + arg + '"') |
|
341 | return |
|
342 | } |
|
343 | if (inclusive === true) { |
|
344 | inpObj.plain = inpObj.plain.substr(x) |
|
345 | } else { |
|
346 | inpObj.plain = inpObj.plain.substr(x + arg.length) |
|
347 | } |
|
348 | } |
|
349 | } |
|
350 | ||
351 | // ===================textFrom================================= |
|
352 | function textTo (inpObj, cmdArgs, inclusive) { |