Skip to content

Commit

Permalink
Add documentation for confusing function
Browse files Browse the repository at this point in the history
  • Loading branch information
imurchie committed Sep 14, 2017
1 parent 8346472 commit fcfa46c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/webview-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@ helpers.procFromWebview = async function (adb, webview) {
let pidIndex = header.indexOf('PID');
let pkgIndex = header.indexOf('NAME');

function slice (line, index) {
/*
* Get the entry based on the position of the header. The entry can be aligned
* either the beginning or the end of the header, so the start of the entry
* can be before the header starts or after. Figure that out.
*/
function getEntry (line, headerIndex) {
// first find the beginning
let start = index;
let start = headerIndex;
if (line[start] === ' ') {
// the entry has not started yet, so move to the right until we have it
while (start < line.length) {
Expand All @@ -122,9 +127,9 @@ helpers.procFromWebview = async function (adb, webview) {
}

for (let line of lines) {
let pidEntry = slice(line, pidIndex);
let pidEntry = getEntry(line, pidIndex);
if (pidEntry === pid) {
pkg = slice(line, pkgIndex);
pkg = getEntry(line, pkgIndex);
logger.debug(`Parsed pid: '${pidEntry}' pkg: '${pkg}' from`);
logger.debug(` ${header}`);
logger.debug(` ${line}`);
Expand Down

0 comments on commit fcfa46c

Please sign in to comment.