SourceFormatX

Overview

Features

Why Use It

Formatting Show

Integration

Screenshots

Documentation

FAQs & Tips

Update History

Award Gallery

Testimonials

License Policy

CodeMorph

CodeToHtml

Java Source Code Formatting Show


Feature

SourceFormatX code formatter bases on powerful syntax parse engines so it can beautify and format source code files with omnifarious styles, even these messy source code examples below:

C/C++ Java C# Delphi (Pascal)
PHP JSP ASP JavaScript
Visual Basic VB.NET VBScript HTML Components
80x86 ASM 8051 ASM CORBA IDL


  Java Source Code Formatting Examples:     Example 1   |   Example 2   |   Example 3   |   Example 4

This Java code formatting example proves the power of SourceFormatX Java Code Formatting Tool's syntax parse engine.

  /* Before Code Formatting */

  package net.jforum.util;/** * Normalizes an URL.
  * Normalization means replacing blank spaces by underlines,
  * changing special chars by its regular form and etc. * @author Rafael Steil
  * @version $Id: URLNormalizer.java,v 1.4 2006/08/20 22:47:42 rafaelsteil Exp $
  */public class URLNormalizer{public static final int LIMIT=30;/**
  * Normalizes an URL.   * The url will be truncated at {@link #LIMIT} chars
  * @param url the url to normalize   * @return the normalized url
  * @see #normalize(String, int, boolean)   */public static String normalize(
  String url){return normalize(url,LIMIT,true);}/**   *
  * @param url the url to normalize
  * @param limit do not process more than <code>limit + 1</code> chars
  * @param friendlyTruncate If <code>true</code>, will try to not cut a word if
  * more than <code>limit</code> chars were processed. It will stop in the next
  * special char   * @return the normalized url   */public static String
  normalize(String url,int limit,boolean friendlyTruncate){char[]chars=
  url.toCharArray();StringBuffer sb=new StringBuffer(url.length());for(int i=0;i<
  chars.length;i++){if(i<=limit||(friendlyTruncate&&i>limit&&sb.charAt(sb.length(
  )-1)!='_')){if(Character.isSpaceChar(chars[i])||chars[i]=='-'){if(
  friendlyTruncate&&i>limit){break;}if(i>0&&sb.charAt(sb.length()-1)!='_'){
  sb.append('_');}}if(Character.isLetterOrDigit(chars[i])){sb.append(chars[i]);}
  else if(friendlyTruncate&&i>limit){break;}}}return sb.toString().toLowerCase();}}


  /* After Code Formatting */

  package net.jforum.util;

  /**
   * Normalizes an URL.
   * Normalization means replacing blank spaces by underlines,
   * changing special chars by its regular form and etc.
   * @author Rafael Steil
   * @version $Id: URLNormalizer.java,v 1.4 2006/08/20 22:47:42 rafaelsteil Exp $
   */

  public class URLNormalizer
  {
    public static final int LIMIT = 30;

    /**
     * Normalizes an URL.
     * The url will be truncated at {@link #LIMIT} chars
     * @param url the url to normalize
     * @return the normalized url
     * @see #normalize(String, int, boolean)
     */

    public static String normalize(String url)
    {
      return normalize(url, LIMIT, true);
    }

    /**
     *
     * @param url the url to normalize
     * @param limit do not process more than <code>limit + 1</code> chars
     * @param friendlyTruncate If <code>true</code>, will try to not cut a word if
     * more than <code>limit</code> chars were processed. It will stop in the next
     * special char
     * @return the normalized url
     */

    public static String normalize(String url, int limit, boolean friendlyTruncate)
    {
      char[] chars = url.toCharArray();

      StringBuffer sb = new StringBuffer(url.length());

      for (int i = 0; i < chars.length; i++) {
        if (i <= limit || (friendlyTruncate && i > limit && sb.charAt(sb.length() - 1) != '_')) {
          if (Character.isSpaceChar(chars[i]) || chars[i] == '-') {
            if (friendlyTruncate && i > limit) {
              break;
            }

            if (i > 0 && sb.charAt(sb.length() - 1) != '_') {
              sb.append('_');
            }
          }

          if (Character.isLetterOrDigit(chars[i])) {
            sb.append(chars[i]);
          }
          else if (friendlyTruncate && i > limit) {
            break;
          }
        }
      }

      return sb.toString().toLowerCase();
    }
  }

Example 1   |   Example 2   |   Example 3   |   Example 4

  Don't waste time on formatting Java source code by hand any more!  Download SourceFormatX Java Free Trial now!