MCPcopy Create free account
hub / github.com/tensorflow/tfjs / split

Function split

tfjs-backend-cpu/src/kernels/StringSplit_impl.ts:20–62  ·  view source on GitHub ↗
(
    str: Uint8Array, delimiters: Uint8Array, skipEmpty: boolean,
    result: Uint8Array[])

Source from the content-addressed store, hash-verified

18import {TypedArray, util} from '@tensorflow/tfjs-core';
19
20function split(
21 str: Uint8Array, delimiters: Uint8Array, skipEmpty: boolean,
22 result: Uint8Array[]): void {
23 if (!str.length) {
24 return;
25 }
26 // When the delimiter is empty, the input is split into individual characters.
27 if (delimiters.length === 0) {
28 for (let i = 0; i < str.length; ++i) {
29 result.push(str.subarray(i, i + 1));
30 }
31 return;
32 }
33 // When there is one delimiter, the input is split only at that delimiter.
34 if (delimiters.length === 1) {
35 const delimiter = delimiters[0];
36 let f = str.indexOf(delimiter);
37 while (f !== -1) {
38 const token = str.subarray(0, f);
39 if (!skipEmpty || token.length !== 0) {
40 result.push(token);
41 }
42 str = str.subarray(f + 1);
43 f = str.indexOf(delimiter);
44 }
45 if (!skipEmpty || str.length !== 0) {
46 result.push(str);
47 }
48 return;
49 }
50 // When there are multiple delimiters, the input is split at every instance
51 // one of the delimiters appears.
52 let tokenStart = 0;
53 for (let i = 0; i < str.length + 1; i++) {
54 if ((i === str.length) || (delimiters.indexOf(str[i]) !== -1)) {
55 const token = str.subarray(tokenStart, i);
56 if (!skipEmpty || token.length !== 0) {
57 result.push(token);
58 }
59 tokenStart = i + 1;
60 }
61 }
62}
63
64export function stringSplitImpl(
65 input: Uint8Array[], delimiter: Uint8Array,

Callers 1

stringSplitImplFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…