Thread: Runescape Text Optimization.

Results 1 to 8 of 8
  1. #1 Runescape Text Optimization. 
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    If you noticed in runescape, if you type something like this,

    Code:
    hi I AM A STRING. and I AM NICE
    It will turn into this

    Code:
    Hi I Am A String. And I Am Nice
    I found an old method in the server that does this, only partially. This will format all text accurately to runescapes format.

    Code:
        public static String optimizeText(String text) {
            boolean endMarker = true;
            String output = "";
            for (int i = 0; i < text.length(); i++) {
                char c = text.charAt(i);
                if (endMarker && c >= 'a' && c <= 'z') {
                    c = Character.toUpperCase(c);
                    endMarker = false;
                } else if (!Character.isWhitespace(text.charAt(i-1)) && i > 1) {
                    c = Character.toLowerCase(c);
                }
                if (c == '.' || c == '!' || c == '?') {
                    endMarker = true;
                }
                output += c;
            }
            return output;
        }
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Aug 2009
    Posts
    120
    Thanks given
    0
    Thanks received
    0
    Rep Power
    17
    isn't it done client-side?
    Reply With Quote  
     

  3. #3  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    Quote Originally Posted by TEHproLEECHR View Post
    isn't it done client-side?
    This can be used for client or server, the code doesn't have any specifics, as its just a string formatting using default character sets. Its also useful for yell-chat, so, thats what I developed it for.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Auruo's Avatar
    Join Date
    Mar 2008
    Age
    32
    Posts
    750
    Thanks given
    21
    Thanks received
    15
    Rep Power
    499
    Quote Originally Posted by bloodargon View Post
    It will turn into this

    Code:
    Hi I Am A String. And I Am Nice
    Correction, it will turn into this:
    Code:
    Hi i am a string. And i am nice
    Gj btw
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Jun 2008
    Posts
    913
    Thanks given
    30
    Thanks received
    94
    Rep Power
    0
    This is already in the 'Misc' class in any winterlove-based server.
    Reply With Quote  
     

  6. #6  
    RedBull
    Guest
    You should rip the methods from the client, converting it to a long and back, that way you can remove invalid chars and save them being saved with their character info .
    Reply With Quote  
     

  7. #7  
    Registered Member

    Join Date
    Jul 2009
    Posts
    597
    Thanks given
    158
    Thanks received
    95
    Rep Power
    632
    Quote Originally Posted by Auruo View Post
    Correction, it will turn into this:
    Code:
    Hi i am a string. And i am nice
    Gj btw
    No it won't in before the first fullstop he capitalized every word..
    Reply With Quote  
     

  8. #8  
    Member

    Join Date
    Sep 2007
    Posts
    614
    Thanks given
    0
    Thanks received
    1
    Rep Power
    0
    Quote Originally Posted by Auruo View Post
    Correction, it will turn into this:
    Code:
    Hi i am a string. And i am nice
    Gj btw
    Correction.
    Code:
     if (endMarker && c >= 'a' && c <= 'z') {
                    c = Character.toUpperCase(c);
                    endMarker = false;
                } else if (!Character.isWhitespace(text.charAt(i-1)) && i > 1) {
                    c = Character.toLowerCase(c);
                }
    It will only lowercase the letter if the character before is NOT a white space, so, "i Ii" is allowed because the second I has a whitespace before.

    Put the method somewhere and test it yourself.

    Quote Originally Posted by Primadude View Post
    This is already in the 'Misc' class in any winterlove-based server.
    But that method will only capitalize after a period and at the beginning. Even in the client, it will still auto-format everything to lower case unless its after a period. This method improves both, using similar techniques, and allows text formatting that matches to runescapes.


    Quote Originally Posted by RedBull View Post
    You should rip the methods from the client, converting it to a long and back, that way you can remove invalid chars and save them being saved with their character info .
    Code:
        public static ArrayList<Character> yellCharacters = new ArrayList<Character>();
    
        public static void setYellCharacters() {
            char[] validChars = {
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                'j', 'k', 'l', 'm', 'n', 'n', 'o', 'p', 'q', 'r',
                's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                'J', 'K', 'L', 'M', 'N', 'N', 'O', 'P', 'Q', 'R',
                'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
                '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '=',
                '+', '{', '[', ']', '}', '|', ';', ':', '"', '<', ',', '.', '>', '/', '?', '`', '~', ' ', '\\', 39};
            for (int i = 0; i < validChars.length; i++) {
                yellCharacters.add(validChars[i]);
            }
        }
    
        public static String filterString(String f, boolean yell) {
            String raw = f;
            String build = "";
            raw = raw.trim();
            if (yell) {
                for (int i = 0; i < raw.length(); i++) {
                    if (!yellCharacters.contains(raw.charAt(i))) {
                        raw.replace(raw.charAt(i), ' ');
                    }
                }
                return raw;
            } else {
                for (int i = 0; i < raw.length(); i++) {
                    Character c = raw.charAt(i);
                    if (Character.isLetterOrDigit(c) || Character.isSpaceChar(c)) {
                        build += c;
                    }
                }
                return build;
            }
        }
    On server load call setYellCharacters().

    This allows dual filtering. If yellMode is false, it will only allow letters, digits, and spaces. Good for name formatting. If its on, it will allow ONLY the characters in the yell array list.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •