Here you can find the source of getMinWhitespace(final List
Parameter | Description |
---|---|
lines | list where each element represents an individual line of sample text |
public static int getMinWhitespace(final List<String> lines)
//package com.java2s; /*/* w ww . jav a 2 s .com*/ * Copyright 2013-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ import java.util.List; public class Main { /** * Gets the minimum amount of leading whitespace in a text block. * * @param lines * list where each element represents an individual line of * sample text * * @return minimum amount of leading whitespace */ public static int getMinWhitespace(final List<String> lines) { int minWhitespace = 0; for (String line : lines) { int lineLeadingWhitespace = getLeadingWhitespace(line); if (lineLeadingWhitespace < minWhitespace || minWhitespace == 0) { minWhitespace = lineLeadingWhitespace; } } return minWhitespace; } /** * Returns the number of leading whitespace characters in a given string. * * @param str * string to check * @return number of leading whitespace characters */ public static int getLeadingWhitespace(final String str) { int pos = 0; while ((pos < str.length()) && (str.charAt(pos) == ' ')) { pos++; } return pos; } }