* Find the first occurence of the given pattern and return * the location as the approximate line number. * * @param {string} src * @param {RegExp} pattern * @returns {number}
(src, pattern)
| 5712 | * @returns {number} |
| 5713 | */ |
| 5714 | function getLineNumber(src, pattern) { |
| 5715 | const index= stringSearch(src, pattern); |
| 5716 | if( index< 0) { |
| 5717 | return -1; |
| 5718 | } |
| 5719 | |
| 5720 | // The importPattern incidentally captures an initial \n in |
| 5721 | // an attempt to reject a . prefix, so we need to offset |
| 5722 | // the line number in that case. |
| 5723 | const adjustment= src[index]=== '\n'? 1: 0; |
| 5724 | |
| 5725 | return stringSplit(stringSlice(src, 0, index), '\n').length+ adjustment; |
| 5726 | } |
| 5727 | |
| 5728 | // ///////////////////////////////////////////////////////////////////////////// |
| 5729 |
no outgoing calls
no test coverage detected