Class UtilFunctions


  • public class UtilFunctions
    extends Object
    TeamCity utility functions
    Since:
    6.0
    • Constructor Detail

      • UtilFunctions

        public UtilFunctions()
    • Method Detail

      • escapeJavaScriptIdentifier

        public static String escapeJavaScriptIdentifier​(@Nullable
                                                        String text)
        escape given text to make it an javascript identifier
        Parameters:
        text - text to escape
        Returns:
        string that could be used as javascript identifier
        Since:
        6.0
      • escapeJavaScript

        public static String escapeJavaScript​(@Nullable
                                              String text,
                                              boolean removeLineFeeds,
                                              boolean forHTMLAttribute)
        escape given text to be used in javascript
        Parameters:
        text - text to escape
        removeLineFeeds - true to make it removing new lines
        forHTMLAttribute - true if escaped text is used inside HTML element's attribute
        Returns:
        string that could be used as javascript identifier
        Since:
        6.0
      • escapeUrlForQuotes

        public static String escapeUrlForQuotes​(@Nullable
                                                String url)
        Escapes url to be used inside quotes using WebUtil.escapeUrlForQuotes()
        Parameters:
        url - the url to escape
        Returns:
        escaped url
        Since:
        7.0
        See Also:
        WebUtil.escapeUrlForQuotes(String)
      • escapeFullUrl

        public static String escapeFullUrl​(@Nullable
                                           String fullUrl)
        Escapes url to be used inside quotes and ensures URL is valid, accepts only http(s):// urls
        Parameters:
        url - the url to escape
        Returns:
        escaped url or null if URL is invalid
        Since:
        2022.04
        See Also:
        WebUtil#escapeFullUrl(String)
      • uniqueId

        public static String uniqueId()
        Generate unique id.
        Returns:
        unique id withing the bounds of the server
      • add

        public static void add​(@NotNull
                               List list,
                               @NotNull
                               Object item)
        Adds the specified item to the list.
        Parameters:
        list - the list
        item - the item to add
      • contains

        public static boolean contains​(@NotNull
                                       Collection collection,
                                       @NotNull
                                       Object item)
        Check whether collection contains specified item.
        Since:
        9.0
      • indexOfNewLine

        public static int indexOfNewLine​(@Nullable
                                         String data)
        Returns index of new line characters
        Since:
        10.0
      • indexOfNewLine

        public static int indexOfNewLine​(@Nullable
                                         String data,
                                         int start,
                                         boolean useHtml)
        Gets index of line separator sequence Uses either \n char of html <br> sequence
        Parameters:
        data - string to search in
        start - start position
        useHtml - switches search to html mode
        Returns:
        index of line separator sequence after start, if there is a non-empty next line, {-1} otherwise
        Since:
        10.0 (26/10/16)
      • lineSeparator

        public static String lineSeparator​(boolean useHtml)
        Gets line separator either for html or for plain text
        Parameters:
        useHtml - flag for using html line separator
        Returns:
        line separator
      • removeTrailingSlash

        public static String removeTrailingSlash​(@NotNull
                                                 String url)
        Removes last slash character from the given URL.
        Returns:
        URL without the last slash character
      • toSet

        public static <E> Set<E> toSet​(@Nullable
                                       E[] array)
        Transform the given array into a Set.
        Parameters:
        array -
        Returns:
        a new Set
        Since:
        2023.11