// ChartWord.java
//
// Copyright (C) 1998 Henrik Bjorkman. All rights reserved. 
// No responsibilities taken. Use on your own risk
//
// This program can show your position on a map.
//
//
// History
//
// 1999-06-19 
// Moved class ChartWord to its own file. 
// Henrik Bjorkman
//
// 2000-06-13
// Changed package name to chartplotter_package.
// Henrik


package chartplotter_package;

import java.io.*;
import java.awt.*;
import java.text.*;


public class ChartWord
{
  // Appends space so that a string with a minimum length of n
  // is returned. Oh yes i forgot to say one extra space is 
  // always appended.
  public static String addSpace(String str,int n)
  {
    while (str.length()<n)
    { 
      str=new String(str+" ");
    }
    return(str+" ");
  }

  // Adds zeroes first so that a string with a minimum length of n
  // is returned.
  public static String addZero(String str,int n)
  {
    while (str.length()<n)
    { 
      str=new String("0"+str);
    }
    return(str);
  }

  // To get a string without the first n words in string str.
  public static String skipWords(String str, int n)
  {
    int i=0;

    while (i<str.length() && Character.isSpaceChar(str.charAt(i))) {i++;}

    while (n>0)
    {
      while (i<str.length() && !Character.isSpaceChar(str.charAt(i))) {i++;}
      while (i<str.length() && Character.isSpaceChar(str.charAt(i))) {i++;}
      n--;
    }
    
    return(str.substring(i));
  }

  // To get the first word in a string.
  public static String getFirstWord(String str) 
  {
    int i=0;
    while (i<str.length() && !Character.isSpaceChar(str.charAt(i))) {i++;}
    return(str.substring(0,i));
  }

  public static String getWord(String str, int n)
  {
    return(getFirstWord(skipWords(str,n)));
  }  

  public static String timeString(long time)
  {
    return(addZero((""+(time/3600000L)%24),2)+":"+
           addZero((""+(time/60000L)%60),2)+":"+
           addZero((""+(time/1000L)%60),2));
  }

  // To replace all '/' in a string with system directory separator. 
  public static String changeSeparator(String str) 
  {
    /*System.out.println("change Separator in "+str);*/
    if (!File.separator.equals("/"))
    {
      int i=0;
      String nstr="";
      for (i=0;i<str.length();i++)
      {
        if (str.charAt(i)=='/') 
        {
          nstr+=File.separator;
        }
        else
        {
          nstr+=str.charAt(i);
        }
      }
      /*System.out.println("changed separator to "+nstr);*/
      return(nstr);
    }
    return(str);
  }
}


