Java String Split by Case split(String pString, String pSeparator, boolean pIgnoreCase)

Here you can find the source of split(String pString, String pSeparator, boolean pIgnoreCase)

Description

split

License

Open Source License

Declaration

public static ArrayList split(String pString, String pSeparator, boolean pIgnoreCase) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * //from w  w  w .  j  ava2s  .c  o m
 * Copyright 2007 Randall
 * 
 * This file is part of gomule.
 * 
 * gomule is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * gomule is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * gomlue; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
 * Fifth Floor, Boston, MA 02110-1301 USA
 *  
 ******************************************************************************/

import java.util.*;

public class Main {
    public static ArrayList split(String pString, String pSeparator, boolean pIgnoreCase) {
        ArrayList lSplit = new ArrayList();
        int lIndex = 0;
        int lSeparator;
        String lSubString;

        // For (faster) uppercase comparing
        String pCompStr;
        String pCompSep;
        if (pIgnoreCase) {
            pCompStr = (pString == null) ? null : pString.toLowerCase();
            pCompSep = (pSeparator == null) ? "," : pSeparator.toLowerCase();
        } else {
            pCompStr = pString;
            pCompSep = pSeparator;
        }

        // In case of lengths not being equal, split while not ignoring case.
        if (pString != null && pCompStr != null && pCompStr.length() != pString.length()) {
            // The compare without lowercase
            pCompStr = pString;
            pCompSep = pSeparator;
        }

        if (pString != null) {
            while (lIndex < pString.length()) {
                // find first Separator starting from lIndex
                lSeparator = pCompStr.indexOf(pCompSep, lIndex); // pCompStr.length()
                if (lSeparator == -1) {
                    lSubString = pString.substring(lIndex);
                    lIndex = pString.length();
                } else {
                    lSubString = pString.substring(lIndex, lSeparator);
                    lIndex = lSeparator + pSeparator.length();
                }
                lSplit.add(lSubString.trim());
            }
        }
        return lSplit;
    }
}

Related

  1. splitByCamelCase(String name)
  2. splitByCharacterTypeCamelCase(String targetName)
  3. splitCamelCase(final String in)
  4. splitCamelCase(final String s)