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

13
LINES

< > BotCompany Repo | #1032383 // safeBashQuote function - single quotes

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (38L/1K).

1  
/** possibly improvable */
2  
sS safeBashQuote(String text) {
3  
  if (text == null) return null;
4  
  return "'" + text
5  
    .replace("\\", "\\\\")
6  
    .replace("'", "\\'")
7  
    .replace("\n", "\\n")
8  
    .replace("\r", "\\r") + "'";
9  
}
10  
11  
sS safeBashQuote(File f) {
12  
  ret safeBashQuote(f.getAbsolutePath());
13  
}

Author comment

Began life as a copy of #1000832

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032383
Snippet name: safeBashQuote function - single quotes
Eternal ID of this version: #1032383/1
Text MD5: 66479fb8e7aacbf642e2afdbb270e571
Transpilation MD5: c08ea45e66595ccd5ef3e897a1abab8a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-02 02:58:31
Source code size: 308 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 69 / 106
Referenced in: [show references]