com.mindoo.domino.jna.utils.StringUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of domino-jna Show documentation
Show all versions of domino-jna Show documentation
Java project to access the HCL Domino C API using Java Native Access (JNA)
The newest version!
package com.mindoo.domino.jna.utils; import java.util.Arrays; import java.util.List; /** * Collection of string utilities * * @author Karsten Lehmann */ public class StringUtil { /** * Returns the nth value of a string array. The first array element is at position 1. * If the array does not have enough entries, the method returns an empty string. * * @param strArr array * @param pos position * @return value */ public static String wWord(String[] strArr, int pos) { return getNth(strArr, pos-1); } /** * Returns the nth value of a string array beginning with position 0. * If the array does not have enough entries, the method returns an empty string. * * @param strArr array * @param index array index * @return value */ public static String getNth(String[] strArr, int index) { if (index
or an empty string * * @param strValue string * @returnnull true
if empty */ public static boolean isEmpty(String strValue) { return strValue==null || strValue.length()==0; } /** * The method checks whether the specified string value is not null and * its size is greater than zero characters * * @param str string * @returntrue
if not empty */ public static boolean isNotEmpty(String str) { return (str != null) && (str.length() > 0); } /** * Repeats a string a number of times * * @param str string * @param repetitions nr of repetitions * @return resulting string */ public static String repeat(String str, int repetitions) { if (repetitions==0) return ""; else if (repetitions==1) return str; char[] chars=new char[str.length()*repetitions]; int index=0; for (int i=0; i=targetLength) return str; StringBuilder sb=new StringBuilder(); if (appendChars) { sb.append(str); while (sb.length() p_sStr.length()) return false; for (int i=0; i p_sStr.length()) return false; int nSubStrLen=p_sSubStr.length(); int nStrLen=p_sStr.length(); int nIdx=1; for (int i=nSubStrLen-1; i>=0; i--) { char cSubStr=p_sSubStr.charAt(i); char cStr=p_sStr.charAt(nStrLen-nIdx); char cSubStrLC=Character.toLowerCase(cSubStr); char cStrLC=Character.toLowerCase(cStr); if (cSubStrLC != cStrLC) return false; nIdx++; } return true; } /** * The method concatenates a list of strings with the given delimiter * * @param p_sStrList string list * @param p_sDelimiter delimiter * @return concatenated strings */ public static String join(List p_sStrList, String p_sDelimiter) { StringBuilder sb=new StringBuilder(); for (int i=0; i 0) sb.append(p_sDelimiter); sb.append(sCurrStr); } return sb.toString(); } /** * Computes the number of bytes a string would allocate if converted to UTF-8 * * @param str string * @return number of bytes */ public static int stringLengthInUTF8(String str) { int retLength = 0; int strLen = str.length(); for (int i = 0; i < strLen; i++) { char c = str.charAt(i); if (c <= 0x7F) { retLength++; } else if (c <= 0x7FF) { retLength += 2; } else if (Character.isHighSurrogate(c)) { retLength += 4; i++; } else { retLength += 3; } } return retLength; } }