001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.util;
015
016/**
017 * Various utility methods for processing strings representing context types.
018 * 
019 * @author Ceki Gulcu
020 * 
021 */
022public class ContentTypeUtil {
023
024    public static boolean isTextual(String contextType) {
025        if (contextType == null) {
026            return false;
027        }
028        return contextType.startsWith("text");
029    }
030
031    public static String getSubType(String contextType) {
032        if (contextType == null) {
033            return null;
034        }
035        int index = contextType.indexOf('/');
036        if (index == -1) {
037            return null;
038        } else {
039            int subTypeStartIndex = index + 1;
040            if (subTypeStartIndex < contextType.length()) {
041                return contextType.substring(subTypeStartIndex);
042            } else {
043                return null;
044            }
045        }
046    }
047}