< prev index next >

jaxws/src/jdk.xml.bind/share/classes/com/sun/codemodel/internal/JJavaName.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  68             if( !isJavaIdentifier(s.substring(0,idx)) )
  69                 return false;
  70 
  71             s = s.substring(idx);
  72             if(s.length()!=0)    s = s.substring(1);    // remove '.'
  73         }
  74         return true;
  75     }
  76 
  77     /**
  78      * <b>Experimental API:</b> converts an English word into a plural form.
  79      *
  80      * @param word
  81      *      a word, such as "child", "apple". Must not be null.
  82      *      It accepts word concatanation forms
  83      *      that are common in programming languages, such as "my_child", "MyChild",
  84      *      "myChild", "MY-CHILD", "CODE003-child", etc, and mostly tries to do the right thing.
  85      *      ("my_children","MyChildren","myChildren", and "MY-CHILDREN", "CODE003-children" respectively)
  86      *      <p>
  87      *      Although this method only works for English words, it handles non-English
  88      *      words gracefully (by just returning it as-is.) For example, "日本語"
  89      *      will be returned as-is without modified, not "日本語s"
  90      *      <p>
  91      *      This method doesn't handle suffixes very well. For example, passing
  92      *      "person56" will return "person56s", not "people56".
  93      *
  94      * @return
  95      *      always non-null.
  96      */
  97     public static String getPluralForm(String word) {
  98         // remember the casing of the word
  99         boolean allUpper = true;
 100 
 101         // check if the word looks like an English word.
 102         // if we see non-ASCII characters, abort
 103         for(int i=0; i<word.length(); i++ ) {
 104             char ch = word.charAt(i);
 105             if(ch >=0x80)
 106                 return word;
 107 
 108             // note that this isn't the same as allUpper &= Character.isUpperCase(ch);
 109             allUpper &= !Character.isLowerCase(ch);


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  68             if( !isJavaIdentifier(s.substring(0,idx)) )
  69                 return false;
  70 
  71             s = s.substring(idx);
  72             if(s.length()!=0)    s = s.substring(1);    // remove '.'
  73         }
  74         return true;
  75     }
  76 
  77     /**
  78      * <b>Experimental API:</b> converts an English word into a plural form.
  79      *
  80      * @param word
  81      *      a word, such as "child", "apple". Must not be null.
  82      *      It accepts word concatanation forms
  83      *      that are common in programming languages, such as "my_child", "MyChild",
  84      *      "myChild", "MY-CHILD", "CODE003-child", etc, and mostly tries to do the right thing.
  85      *      ("my_children","MyChildren","myChildren", and "MY-CHILDREN", "CODE003-children" respectively)
  86      *      <p>
  87      *      Although this method only works for English words, it handles non-English
  88      *      words gracefully (by just returning it as-is.) For example, "{@literal 日本語}"
  89      *      will be returned as-is without modified, not "{@literal 日本語s}"
  90      *      <p>
  91      *      This method doesn't handle suffixes very well. For example, passing
  92      *      "person56" will return "person56s", not "people56".
  93      *
  94      * @return
  95      *      always non-null.
  96      */
  97     public static String getPluralForm(String word) {
  98         // remember the casing of the word
  99         boolean allUpper = true;
 100 
 101         // check if the word looks like an English word.
 102         // if we see non-ASCII characters, abort
 103         for(int i=0; i<word.length(); i++ ) {
 104             char ch = word.charAt(i);
 105             if(ch >=0x80)
 106                 return word;
 107 
 108             // note that this isn't the same as allUpper &= Character.isUpperCase(ch);
 109             allUpper &= !Character.isLowerCase(ch);


< prev index next >