Example usage for com.google.common.primitives Chars indexOf

List of usage examples for com.google.common.primitives Chars indexOf

Introduction

In this page you can find the example usage for com.google.common.primitives Chars indexOf.

Prototype

public static int indexOf(char[] array, char[] target) 

Source Link

Document

Returns the start position of the first occurrence of the specified target within array , or -1 if there is no such occurrence.

Usage

From source file:com.google.devtools.build.lib.packages.util.SubincludePreprocessor.java

@Override
public Preprocessor.Result preprocess(Path buildFilePath, byte[] buildFileBytes, String packageName,
        Globber globber, Set<String> ruleNames) throws IOException, InterruptedException {
    StoredEventHandler eventHandler = new StoredEventHandler();
    char content[] = FileSystemUtils.convertFromLatin1(buildFileBytes);
    while (true) {
        Matcher matcher = SUBINCLUDE_REGEX.matcher(CharBuffer.wrap(content));
        if (!matcher.find()) {
            break;
        }//ww  w. j  a  v a 2s  . c o  m
        String name = matcher.group(1);
        String path = resolveSubinclude(name);

        char subContent[];
        if (path.isEmpty()) {
            // This location is not correct, but will do for testing purposes.
            eventHandler.handle(Event.error(Location.fromFile(buildFilePath),
                    "Cannot find subincluded file \'" + name + "\'"));
            // Emit a mocksubinclude(), so we know to preprocess again if the file becomes
            // visible. We cannot fail the preprocess here, as it would drop the content.
            subContent = new char[0];
        } else {
            // TODO(bazel-team): figure out the correct behavior for a non-existent file from an
            // existent package.
            subContent = FileSystemUtils.readContentAsLatin1(fileSystem.getPath(path));
        }

        String mock = "\nmocksubinclude('" + name + "', '" + path + "')\n";

        content = Chars.concat(Arrays.copyOf(content, matcher.start()), mock.toCharArray(), subContent,
                Arrays.copyOfRange(content, matcher.end(), content.length));
    }

    if (Chars.indexOf(content, TRANSIENT_ERROR.toCharArray()) >= 0) {
        throw new IOException("transient error requested in " + buildFilePath.asFragment());
    }

    return Preprocessor.Result.success(ParserInputSource.create(content, buildFilePath.asFragment()),
            eventHandler.hasErrors(), eventHandler.getEvents());
}