Replaces all . and / with _ and removes all spaces and double/single quotes.
Chomps any trailing . or _ character.

@param allowDottedKeys whether we remove the dots or not.
14531
public static String cleanupStr(String name, boolean allowDottedKeys) {
		if (name == null) {
			return null;
		}
		Pattern pattern;
		if (!allowDottedKeys) {
			pattern = DOT_SLASH_UNDERSCORE_PAT;
		} else {
			pattern = SLASH_UNDERSCORE_PAT;
		}
		String clean = pattern.matcher(name).replaceAll("_");
		clean = SPACE_PAT.matcher(clean).replaceAll("");
		clean = org.apache.commons.lang.StringUtils.chomp(clean, ".");
		clean = org.apache.commons.lang.StringUtils.chomp(clean, "_");
		return clean;
	}
1000498
protected function replacePlaceholders(
        /*# string */ $key,
        array &$bindings,
        array $settings
    )/*# : string */ {
        $escape = $this->escape;

        $value = $this->parameters[$key];
        if ($settings['positionedParam']) {
            $bindings[] = $value;
            return '?';
        } elseif ($settings['namedParam'] && $this->isNamedParam($value)) {
            return $value;
        } else {
            return $escape($value);
        }
    }
234577
private boolean filteredKey(@NonNull CoreConfiguration config, @NonNull String key) {
        for (String regex : config.excludeMatchingSharedPreferencesKeys()) {
            if (key.matches(regex)) {
                return true;
            }
        }
        return false;
    }
594615
@Override
    public String tagKey(String key) {
        String conventionKey = NamingConvention.snakeCase.tagKey(key);

        String sanitized = tagKeyChars.matcher(conventionKey).replaceAll("_");
        if (!Character.isLetter(sanitized.charAt(0))) {
            sanitized = "m_" + sanitized;
        }
        return sanitized;
    }
171651
public static String removeEscapeChars( String origKey ) {
        StringBuilder sb = new StringBuilder();

        boolean prevWasEscape = false;
        for ( char c : origKey.toCharArray() ) {
            if ( '\\' == c ) {
                if ( prevWasEscape ) {
                    sb.append( c );
                    prevWasEscape = false;
                }
                else {
                    prevWasEscape = true;
                }
            }
            else {
                sb.append( c );
                prevWasEscape = false;
            }
        }

        return sb.toString();
    }
640941
def escapePlaceholders(self,inputString):
        
        escaped = inputString.replace(MapConstants.placeholder,'\\'+MapConstants.placeholder)
        escaped = escaped.replace(MapConstants.placeholderFileName,'\\'+MapConstants.placeholderFileName)
        escaped = escaped.replace(MapConstants.placeholderPath,'\\'+MapConstants.placeholderPath)
        escaped = escaped.replace(MapConstants.placeholderExtension,'\\'+MapConstants.placeholderExtension)
        escaped = escaped.replace(MapConstants.placeholderCounter,'\\'+MapConstants.placeholderCounter)
        return escaped
1362387
public static Set<String> retainMatchingKeys(Counter<String> counter, List<Pattern> matchPatterns) {
    Set<String> removed = new HashSet<String>();
    for (String key : counter.keySet()) {
      boolean matched = false;
      for (Pattern pattern : matchPatterns) {
        if (pattern.matcher(key).matches()) {
          matched = true;
          break;
        }
      }
      if (!matched) {
        removed.add(key);
      }
    }
    for (String key : removed) {
      counter.remove(key);
    }
    return removed;
  }
885702
private String stripSuffix(final String input, final String searchString) {
        final String stripped = input.replace(searchString, "");
        return stripped.trim();
    }
354298
function (key, regexp, replacement, editor) {
            key = key.toLowerCase();

            return getPreviousKeyForEditing(key, editor)
            .then(bindr(Result.andThen, editOnlyWhenPreviousKeyExists))
            .then(bindr(Result.andThen, function (description) {
                const old_message = description.message;
                const new_message = old_message
                    .replace(regexp, replacement)
                    .replace(/\s+/, " ");

                if (old_message === new_message) {
                    return Fail("unchanged");
                }

                if (new_message.length > maxMessageLength) {
                    return Fail("message-length-exceeded");
                }

                if (new_message === "") {
                    return Fail("no-message-left");
                }

                description.message = new_message;
                description.editor = editor;
                description.time = now();

                return Ok(description);
            }))
            .then(bindr(Result.andThen, beforeUpdate))
            .then(bindr(Result.map, function (value) {
                db.set(key, value);
                return value;
            }));
        }
601291
public static String convertToKubernetesName(String text, boolean allowDots) {
        String lower = text.toLowerCase();
        StringBuilder builder = new StringBuilder();
        boolean started = false;
        char lastCh = ' ';
        for (int i = 0, last = lower.length() - 1; i <= last; i++) {
            char ch = lower.charAt(i);
            boolean digit = ch >= '0' && ch <= '9';
            // names cannot start with a digit so lets add a prefix
            if (digit && builder.length() == 0) {
                builder.append(DIGIT_PREFIX);
            }
            if (!(ch >= 'a' && ch <= 'z') && !digit) {
                if (ch == '/') {
                    ch = '.';
                } else if (ch != '.' && ch != '-') {
                    ch = '-';
                }
                if (!allowDots && ch == '.') {
                    ch = '-';
                }
                if (!started || lastCh == '-' || lastCh == '.' || i == last) {
                    continue;
                }
            }
            builder.append(ch);
            started = true;
            lastCh = ch;
        }
        return builder.toString();
    }
1283527
private void stripAsterisk(final StringBuilder javaDoc) {
		int index = javaDoc.indexOf("*");
		while (index != -1) {
			javaDoc.replace(index, index + 1, "");
			index = javaDoc.indexOf("*");
		}
	}
1254243
def slugify(value, allow_dots=False, allow_unicode=False):
    
    if allow_dots:
        pattern = _re_pattern_allow_dots
    else:
        pattern = _re_pattern

    value = six.text_type(value)
    if allow_unicode:
        value = unicodedata.normalize('NFKC', value)
        value = pattern.sub('', value).strip().lower()
        return _re_spaces.sub('-', value)
    value = unicodedata.normalize('NFKD', value).encode(
        'ascii', 'ignore').decode('ascii')
    value = pattern.sub('', value).strip().lower()
    return _re_spaces.sub('-', value)
659439
function replaceWithPatterns( src, patterns ){
    return _.reduce(
        patterns,
        function( replacedCode, replacement, pattern ){
            return replacedCode.replace( new RegExp( pattern, "gi" ), replacement, "gi" );
        },
        src
    );
}
1265001
def permitted_scalar_filter(params, permitted_key)
        permitted_key = permitted_key.to_s

        if has_key?(permitted_key) && permitted_scalar?(self[permitted_key])
          params[permitted_key] = self[permitted_key]
        end

        each_key do |key|
          next unless key =~ /\(\d+[if]?\)\z/
          next unless $~.pre_match == permitted_key

          params[key] = self[key] if permitted_scalar?(self[key])
        end
      end
538670
def dotted_completion(cls, line, sorted_keys, compositor_defs):
        
        completion_key, suggestions = None, []
        tokens = [t for t in reversed(line.replace('.', ' ').split())]
        for i, token in enumerate(tokens):
            key_checks =[]
            if i >= 0:  # Undotted key
                key_checks.append(tokens[i])
            if i >= 1:  # Single dotted key
                key_checks.append('.'.join([key_checks[-1], tokens[i-1]]))
            if i >= 2:  # Double dotted key
                key_checks.append('.'.join([key_checks[-1], tokens[i-2]]))
            # Check for longest potential dotted match first
            for key in reversed(key_checks):
                if key in sorted_keys:
                    completion_key = key
                    depth = completion_key.count('.')
                    suggestions = [k.split('.')[depth+1] for k in sorted_keys
                                   if k.startswith(completion_key+'.')]
                    return completion_key, suggestions
            # Attempting to match compositor definitions
            if token in compositor_defs:
                completion_key = compositor_defs[token]
                break
        return completion_key, suggestions
1020146
def clean_filename(s, minimal_change=False):
    

    # First, deal with URL encoded strings
    h = html_parser.HTMLParser()
    s = h.unescape(s)
    s = unquote_plus(s)

    # Strip forbidden characters
    # https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
    s = (
        s.replace(':', '-')
        .replace('/', '-')
        .replace('<', '-')
        .replace('>', '-')
        .replace('"', '-')
        .replace('\\', '-')
        .replace('|', '-')
        .replace('?', '-')
        .replace('*', '-')
        .replace('\x00', '-')
        .replace('\n', ' ')
    )

    # Remove trailing dots and spaces; forbidden on Windows
    s = s.rstrip(' .')

    if minimal_change:
        return s

    s = s.replace('(', '').replace(')', '')
    s = s.rstrip('.')  # Remove excess of trailing dots

    s = s.strip().replace(' ', '_')
    valid_chars = '-_.()%s%s' % (string.ascii_letters, string.digits)
    return ''.join(c for c in s if c in valid_chars)
1013711
def widont(value, autoescape=None):
    
    esc = autoescape and conditional_escape or (lambda x: x)

    def replace(matchobj):
        return '&nbsp;%s' % matchobj.group(1)

    value = END_PUNCTUATION_WIDONT_REGEXP.sub(replace, esc(smart_text(value)))
    value = WIDONT_REGEXP.sub(replace, value)
    value = DOUBLE_SPACE_PUNCTUATION_WIDONT_REGEXP.sub(replace, value)

    return mark_safe(value)