hpstring.java

来自「一个简单的visio程序。」· Java 代码 · 共 2,075 行 · 第 1/5 页

JAVA
2,075
字号

                            case Variant.V_VAR:
                            total += 16 * maxelem;
                            break;

                            default:
                                throw new HpException(13, "Type mismatch");
                        }
                    }
                    else
                    {
                        total += Length( variant);
                    }
                }
                length = total;
                break;

        	default:
        	    throw new HpException(13,"Type mismatch");
    	}

        return length ;
    }


    public static short LEN(boolean boo_str) throws HpException
    {
		return 2;
	}

    public static short LEN(HByte byt_str) throws HpException
    {
        return 1;
	}

    public static short LEN(short sh_str) throws HpException
    {
        return 2;
	}

    public static short LEN(int i_str) throws HpException
    {
        return 4;
	}	

    public static short LEN(float f_str) throws HpException
    {
        return 4;
	}

    public static short LEN(double d_str) throws HpException
    {
        short length=0;
	    String  dblstr = Double.toString(d_str);

	    int   ePos = dblstr.indexOf('E' );
	    if( ePos!=-1 )
	    {
	        String str1 = dblstr.substring(0,ePos);
	        length = (short)(str1.length()-1);
	    }
	    else
	        length = 8;
	        
	    return length;
	}
	
    public static short LEN(HCurr vc_str) throws HpException
    {
        return 8;
	}
	
    public static short LEN(HDate dt_str) throws HpException
    {
        return 8;
	}
	
    public static int LEN(fixedString fixed_str) throws HpException
    {
		return fixed_str.getLength();
	}

    public static int LEN(String str) throws HpException
    {
		return str.length();
	}

    /**
     *Mid[$](string, start[, length])
     *Mid$() Returns a specified number of characters from a string.
     *Mid() Returns a specified number of characters from a variant string.
     *string   String expression from which characters are returned.If string contains
               Null, Null is returned.
     *start	   Character position in string at which the part to be taken begins. If
               start is greater than the number of characters in string, Mid returns
               a zero-length string.
     *length   Number of characters to return.  If omitted or if there are fewer than
               length characters in the text (including the character at start), all
               characters from the start position to the end of the string are returned.
     *Note
        MidB is provided for use with byte data contained in a string.  Instead of
        specifying the number of characters, the arguments  specify numbers of bytes.
     */
    public static String MID$(Variant  varstr, Variant varstart) throws HpException
    {
        String      result ,str;

        int   start = dbl2int( get_db(varstart) );
        if( start<=0 || start>65535 )
            throw new HpException(95,"Invalid procedure call");

        str = get_str( varstr);
        if( start>str.length() )
            result = "";
        else
            result = str.substring( start-1);

        return  result;
    }

    /*--- FUNCTION: MID$(string,long,long) ---*/
    public static String MID$(Variant  varstr, Variant varstart, Variant varplacelen) throws HpException
    {
        String      result="",  str;
       
		int         start = dbl2int( get_db(varstart) );
        int         placelen = dbl2int( get_db(varplacelen));
        if( start<=0 || start>65535 || placelen<0 || placelen>65535 )
            throw new HpException(95,"Invalid procedure call");

        str = get_str( varstr);
     
		if( start>str.length() )
        {
            result = "";
        }
        else if( placelen<str.length() )
        {
        	if( start+placelen > str.length() )
        	    result = str.substring( start-1);
        	else
        		result = str.substring( start-1,placelen+start-1 );
        }
        else
        {
        	result = str.substring(start-1);
        }

        return   result;
    }

    /*--- FUNCTION: Mid(string,long) ---*/
    public static Variant MID(Variant  varstr, Variant varstart) throws HpException
    {
        int     type;

        type = varstr.getType();
        if( type==Variant.V_NULL )
            return new VNull();
        else
        {
            return new VString( MID$(varstr, varstart) );
        }
    }

    /*--- FUNCTION: MID(string,long,long) ---*/
    public static Variant MID(Variant  varstr, Variant start, Variant placelen)
    	throws HpException
    {
    	int type = varstr.getType();
       	if( type==Variant.V_NULL )
    	    return  new VNull();
    	else
    	{
        	return new VString(MID$(varstr , start, placelen) );
        }
    }

    /**
     *LTrim[$](string)
     *RTrim[$](string)
     *Trim[$](string)
     *Returns a copy of a string without leading spaces (LTrim),trailing spaces (RTrim),
     *or both leading and trailing spaces (Trim).LTrim$(),RTrim$(),Trim$() return a
	 * string, LTrim(),RTrim(),Trim() return a variant string.
     *The string argument is any valid string expression.  If string contains Null,
     *Null is returned
     */
    public static String RTRIM$(Variant  varstr) throws HpException
    {
        String  str = get_str(varstr);
        return  RTRIM$( str);
    }

    
    public static String RTRIM$(boolean bool_str) throws HpException
    {
        return (new Boolean(bool_str)).toString();
    }
    
    public static String RTRIM$(HByte byt_str) throws HpException
    {
        return byt_str.strValue();
    }
    
    public static String RTRIM$(short str) throws HpException
    {
        return Short.toString(str);
    }

    public static String RTRIM$(int i_str) throws HpException
    {
        return Integer.toString(i_str);
    }
    
    public static String RTRIM$(float  f_str) throws HpException
    {
        return Float.toString( f_str);
    }
    
    public static String RTRIM$(double d_str) throws HpException
    {
        return Double.toString(d_str);
    }

    public static String RTRIM$(HCurr vc_str) throws HpException
    {
        return vc_str.strValue();
    }
    
    public static String RTRIM$(HDate dt_str) throws HpException
    {
        return dt_str.strValue();
    }
    
    public static String RTRIM$(fixedString fixed_str) throws HpException
    {
        return RTRIM$( fixed_str.strValue() );
    }
    
    public static String RTRIM$(String str) throws HpException
    {
		String result=null;

        if(str.equals(""))
        {
        	result = "";
        }
        else
        {
        	int      strlen;
        	strlen = str.length();
        	while( str.charAt(strlen-1) == ' ')
        	{
        	    strlen--;
        	    if(strlen==0)
        		break;
            }

        	if(strlen==0)
                result = "";
        	else
        	    result = str.substring( 0,strlen );
        }

        return result;
    }


    /*--- FUNCTION: RTrim(string) ---*/
    public static Variant RTRIM(Variant varstr) throws HpException
    {
    	Variant     v = new Variant();

    	int type = varstr.getType();
    	if(type==Variant.V_NULL )
    	    return new VNull();
    	else
    	{
			String str = varstr.strValue();
			String result;

			if(str.equals(""))
			{
        		result = "";
			}
			else
			{
        		int      strlen;
        		strlen = str.length();
        		while( str.charAt(strlen-1) == ' ')
        		{
        			strlen--;
        			if(strlen==0)
        			break;
				}

        		if(strlen==0)
					result = "";
        		else
        			result = str.substring( 0,strlen );
			}
        	return new VString( result);
        }
    }

    
    public static Variant RTRIM(boolean bool_str) throws HpException
    {
        return new VString( (new Boolean(bool_str)).toString() );
    }
    
    public static Variant RTRIM(HByte byt_str) throws HpException
    {
        return new VString(byt_str.strValue() );
    }
    
    public static Variant RTRIM(short str) throws HpException
    {
        return new VString( Short.toString(str) );
    }

    public static Variant RTRIM(int i_str) throws HpException
    {
        return new VString(Integer.toString(i_str));
    }
    
    public static Variant RTRIM(float  f_str) throws HpException
    {
        return new VString(Float.toString( f_str));
    }
    
    public static Variant RTRIM(double d_str) throws HpException
    {
        return new VString(Double.toString(d_str));
    }

    public static VString RTRIM(HCurr vc_str) throws HpException
    {
        return new VString( vc_str.strValue());
    }
    
    public static Variant RTRIM(HDate dt_str) throws HpException
    {
        return new VString( dt_str.strValue() );
    }
    
    public static VString RTRIM(fixedString fixed_str) throws HpException
    {
        return new VString(RTRIM$( fixed_str.strValue() ));
    }
    
    public static Variant RTRIM(String str) throws HpException
    {
		String result=null;

        if(str.equals(""))
        {
        	result = "";
        }
        else
        {
        	int      strlen;
        	strlen = str.length();
        	while( str.charAt(strlen-1) == ' ')
        	{
        	    strlen--;
        	    if(strlen==0)
        		break;
            }

        	if(strlen==0)
                result = "";
        	else
        	    result = str.substring( 0,strlen );
        }

        return new VString( result );
    }



    /*--- FUNCTION: LTrim$(string) ---*/
    public static String LTRIM$(Variant varstr) throws HpException
    {
        String  str = get_str(varstr);
        return LTRIM$(str);
    }
    
    public static String LTRIM$(boolean bool_str) throws HpException
    {
        return (new Boolean(bool_str)).toString();
    }

    public static String LTRIM$(HByte byt_str) throws HpException
    {
        return  byt_str.strValue();
    }

    public static String LTRIM$(short sh_str) throws HpException
    {
        return Short.toString(sh_str);
    }

    public static String LTRIM$(int i_str) throws HpException
    {
        return Integer.toString(i_str);
    }

    public static String LTRIM$(float f_str) throws HpException
    {
        return Float.toString(f_str);
    }
    
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?