tikhomirov@616: /* tikhomirov@616: * Copyright (c) 2013 TMate Software Ltd tikhomirov@616: * tikhomirov@616: * This program is free software; you can redistribute it and/or modify tikhomirov@616: * it under the terms of the GNU General Public License as published by tikhomirov@616: * the Free Software Foundation; version 2 of the License. tikhomirov@616: * tikhomirov@616: * This program is distributed in the hope that it will be useful, tikhomirov@616: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@616: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@616: * GNU General Public License for more details. tikhomirov@616: * tikhomirov@616: * For information on how to redistribute this software under tikhomirov@616: * the terms of a license other than GNU General Public License tikhomirov@616: * contact TMate Software at support@hg4j.com tikhomirov@616: */ tikhomirov@616: package org.tmatesoft.hg.internal; tikhomirov@616: tikhomirov@616: import java.util.regex.Matcher; tikhomirov@616: import java.util.regex.Pattern; tikhomirov@616: tikhomirov@616: import org.tmatesoft.hg.util.PathRewrite; tikhomirov@616: tikhomirov@616: /** tikhomirov@616: *
Directory names ending in .i or .d have .hg appendedtikhomirov@616: * tikhomirov@616: * @see http://mercurial.selenic.com/wiki/FileFormats#data.2F tikhomirov@616: * @author Artem Tikhomirov tikhomirov@616: * @author TMate Software Ltd. tikhomirov@616: */ tikhomirov@616: final class EncodeDirPathHelper implements PathRewrite { tikhomirov@616: private final Pattern suffix2replace; tikhomirov@616: tikhomirov@616: public EncodeDirPathHelper() { tikhomirov@616: suffix2replace = Pattern.compile("\\.([id]|hg)/"); tikhomirov@616: } tikhomirov@616: tikhomirov@616: public CharSequence rewrite(CharSequence p) { tikhomirov@616: Matcher suffixMatcher = suffix2replace.matcher(p); tikhomirov@616: CharSequence path; tikhomirov@616: // Matcher.replaceAll, but without extra toString tikhomirov@616: boolean found = suffixMatcher.find(); tikhomirov@616: if (found) { tikhomirov@616: StringBuffer sb = new StringBuffer(p.length() + 20); tikhomirov@616: do { tikhomirov@616: suffixMatcher.appendReplacement(sb, ".$1.hg/"); tikhomirov@616: } while (found = suffixMatcher.find()); tikhomirov@616: suffixMatcher.appendTail(sb); tikhomirov@616: path = sb; tikhomirov@616: } else { tikhomirov@616: path = p; tikhomirov@616: } tikhomirov@616: return path; tikhomirov@616: } tikhomirov@616: tikhomirov@616: }