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)

1  
sS fileNameEncode_safeChars = " "; //" ()[]#";
2  
3  
sS fileNameEncode(S s) {
4  
  s = dropLeadingDots(s); // don't produce file names starting with a dot!
5  
  new StringBuilder buf;
6  
  int n = l(s);
7  
  for (int i = 0; i < n; i++) {
8  
    char c = s.charAt(i);
9  
    if (contains(fileNameEncode_safeChars, c))
10  
      buf.append(c);
11  
    else
12  
      buf.append(urlencode(str(c)));
13  
  }
14  
  ret str(buf);
15  
}

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: 551 / 585
Version history: 11 change(s)
Referenced in: [show references]