/* * VITacademics * Copyright (C) 2015 Aneesh Neelam <neelam.aneesh@gmail.com> * Copyright (C) 2015 Saurabh Joshi <saurabhjoshi94@outlook.com> * Copyright (C) 2015 Gaurav Agerwala <gauravagerwala@gmail.com> * Copyright (C) 2015 Karthik Balakrishnan <karthikb351@gmail.com> * Copyright (C) 2015 Pulkit Juneja <pulkit.16296@gmail.com> * Copyright (C) 2015 Hemant Jain <hemanham@gmail.com> * Copyright (C) 2015 Darshan Mehta <darshanmehta17@gmail.com> * * This file is part of VITacademics. * * VITacademics 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 3 of the License, or * (at your option) any later version. * * VITacademics 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 VITacademics. If not, see <http://www.gnu.org/licenses/>. */ package com.karthikb351.vitinfo2.utility; import android.support.annotation.Nullable; public class StringUtils { @Nullable public static String toTitleCase(String string) { if (string == null) { return null; } boolean space = true; StringBuilder builder = new StringBuilder(string); final int len = builder.length(); for (int i = 0; i < len; ++i) { char c = builder.charAt(i); if (space) { if (!Character.isWhitespace(c)) { // Convert to title case and switch out of whitespace mode. builder.setCharAt(i, Character.toTitleCase(c)); space = false; } } else if (Character.isWhitespace(c)) { space = true; } else { builder.setCharAt(i, Character.toLowerCase(c)); } } return builder.toString(); } public static boolean checkString(String string) { return string != null && !string.isEmpty(); } }