1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-07-17 02:44:04 +02:00
Gadgetbridge/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/util/StringUtils.java

69 lines
2.0 KiB
Java
Raw Normal View History

2017-03-10 14:53:19 +01:00
/* Copyright (C) 2017 Carsten Pfeiffer, João Paulo Barraca
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.util;
import android.content.Context;
import android.support.annotation.NonNull;
import nodomain.freeyourgadget.gadgetbridge.R;
public class StringUtils {
public static String truncate(String s, int maxLength){
if (s == null) {
return "";
}
int length = Math.min(s.length(), maxLength);
if(length < 0) {
return "";
}
return s.substring(0, length);
}
public static String pad(String s, int length){
return pad(s, length, ' ');
}
public static String pad(String s, int length, char padChar){
while(s.length() < length) {
s += padChar;
}
return s;
}
@NonNull
public static String formatSender(String sender, Context context) {
if (sender == null || sender.length() == 0) {
return "";
}
return context.getString(R.string.StringUtils_sender, sender);
}
@NonNull
public static String getFirstOf(String first, String second) {
if (first != null && first.length() > 0) {
return first;
}
if (second != null) {
return second;
}
return "";
}
}