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

15
LINES

< > BotCompany Repo | #1011389 // fileNameEncode - hopefully safe on all platforms; takes any string; not guaranteed to stay the same in the future

JavaX fragment (include)

sS fileNameEncode_safeChars = " "; //" ()[]#";

sS fileNameEncode(S s) {
  s = dropLeadingDots(s); // don't produce file names starting with a dot!
  new StringBuilder buf;
  int n = l(s);
  for (int i = 0; i < n; i++) {
    char c = s.charAt(i);
    if (contains(fileNameEncode_safeChars, c))
      buf.append(c);
    else
      buf.append(urlencode(str(c)));
  }
  ret str(buf);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1011389
Snippet name: fileNameEncode - hopefully safe on all platforms; takes any string; not guaranteed to stay the same in the future
Eternal ID of this version: #1011389/12
Text MD5: f07e18ac11e679a2ef1f932b3ba7f2ca
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-22 23:47:43
Source code size: 396 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 552 / 585
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)