Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1002497 - smartIndexOf - returns l(s) if not found

JavaX fragment (include)

// returns l(s) if not found
static int smartIndexOf(S s, S sub, int i) {
  if (s == null) ret 0;
  i = s.indexOf(sub, min(i, l(s)));
  ret i >= 0 ? i : l(s);
}

static int smartIndexOf(S s, int i, char c) {
  ret smartIndexOf(s, c, i);
}

static int smartIndexOf(S s, char c, int i) {
  if (s == null) ret 0;
  i = s.indexOf(c, min(i, l(s)));
  ret i >= 0 ? i : l(s);
}

static int smartIndexOf(S s, S sub) {
  ret smartIndexOf(s, sub, 0);
}

static int smartIndexOf(S s, char c) {
  ret smartIndexOf(s, c, 0);
}

static <A> int smartIndexOf(L<A> l, A sub) {
  ret smartIndexOf(l, sub, 0);
}

static <A> int smartIndexOf(L<A> l, int start, A sub) {
  ret smartIndexOf(l, sub, start);
}

static <A> int smartIndexOf(L<A> l, A sub, int start) {
  int i = indexOf(l, sub, start);
  ret i < 0 ? l(l) : i;
}

download  show line numbers  debug dex   

Travelled to 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1002497
Snippet name: smartIndexOf - returns l(s) if not found
Eternal ID of this version: #1002497/4
Text MD5: 792cd53cec4c83e857ffdd61d265564a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-02-27 01:26:19
Source code size: 839 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 468 / 417
Version history: 3 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1002497 & http://1002497.tinybrain.de