From 366ca37ff9cf1c64c69df2094814315cb4a69c77 Mon Sep 17 00:00:00 2001 From: Franco Raimondi Date: Fri, 18 Dec 2020 08:27:32 -0800 Subject: [PATCH] apache commons lang3 string utils model (#1346) Summary: Small model for a couple of StringUtils functions Pull Request resolved: https://github.com/facebook/infer/pull/1346 Reviewed By: ngorogiannis Differential Revision: D25638009 Pulled By: jvillard fbshipit-source-id: 01db6d09e --- .../src/org/apache/commons/lang3/NOTICE.txt | 5 ++ .../org/apache/commons/lang3/StringUtils.java | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 infer/models/java/src/org/apache/commons/lang3/NOTICE.txt create mode 100644 infer/models/java/src/org/apache/commons/lang3/StringUtils.java diff --git a/infer/models/java/src/org/apache/commons/lang3/NOTICE.txt b/infer/models/java/src/org/apache/commons/lang3/NOTICE.txt new file mode 100644 index 000000000..72eb0990a --- /dev/null +++ b/infer/models/java/src/org/apache/commons/lang3/NOTICE.txt @@ -0,0 +1,5 @@ +Apache Commons Lang +Copyright 2001-2020 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (https://www.apache.org/). diff --git a/infer/models/java/src/org/apache/commons/lang3/StringUtils.java b/infer/models/java/src/org/apache/commons/lang3/StringUtils.java new file mode 100644 index 000000000..38a7c5212 --- /dev/null +++ b/infer/models/java/src/org/apache/commons/lang3/StringUtils.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * The method below are copied verbatim from: + * https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/StringUtils.java + * to provide a model for biabduction analysis + */ + +package org.apache.commons.lang3; + +public final class StringUtils { + + public static boolean isNotEmpty(final CharSequence cs) { + return !isEmpty(cs); + } + + public static boolean isEmpty(final CharSequence cs) { + return cs == null || cs.length() == 0; + } + + public static boolean isBlank(final CharSequence cs) { + final int strLen = length(cs); + if (strLen == 0) { + return true; + } + for (int i = 0; i < strLen; i++) { + if (!Character.isWhitespace(cs.charAt(i))) { + return false; + } + } + return true; + } + + public static int length(final CharSequence cs) { + return cs == null ? 0 : cs.length(); + } + +}