format.java

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

JAVA
2,266
字号
				else {
					if (fm.equals("")) {
						if (isNumOrDate(new VString(tmp)))
							return new VString("");
						else return new VString(tmp);
					}
					break;
				}
			}

			String fmy = fm;
			String fmf = fm;

			index = fmy.indexOf('\\');
			boolean yes = false;
			if(index != -1) yes = true;

			StringBuffer sb86 = new StringBuffer();
			for(i = 0; i<fm.length(); i++)
			{
				if (fm.charAt(i) != '\\')
					sb86.append(fm.charAt(i));
				else if (i != fm.length() - 1) {
					if (fm.charAt(i+1) == ',' && fm.charAt(i+2) == ',')
						throw new HpException(5, "Invalid procedure call");
					else  i++;
				}
			}
			if (sb86.length() == 0) return new VString(tmp);
			fm = sb86.toString();

			char c = fm.charAt(0);

			if(c=='.')
				tflag = true;

			if(c==':') {
				if(fm.indexOf(':') != -1)
					return new VString(tmp);
				else if(fm.indexOf('.') != -1)
					return new VString(fm);
				else
					throw new HpException(13, "Type mismatch");
			}

			if(c=='/') {
				if (tmp.indexOf('/') != -1)
					return new VString(tmp);
				else if (tmp.indexOf('.') != -1)
					return new VString(fm);
				else {
					if (isNumOrDate(new VString(tmp)))
						return new VString(fm);
					else return new VString(tmp);
					//throw new HpException(13, "Type mismatch");
				}
			}

			if(c == 'e' || c == 'E')
				throw new HpException(5, "Invalid procedure call");

			if(c == 't' || c == 'T') {
				if (fm.length() < 5)
					throw new HpException(5, "Invalid procedure call");
				else if (!fm.substring(0,5).equalsIgnoreCase("ttttt"))
				throw new HpException(5, "Invalid procedure call");
			}

			index = 0;
			int indexof = -1;
			sb86 = new StringBuffer();
			for(i = 0; i < fm.length(); i++) {
				c = fm.charAt(i);
				if (c == '%')
				{
					int is0 = 0;
					for (is0 = 0; is0 < fm.length(); is0++)
					{
						if(is_numformat(fm.charAt(is0)))
							{index = is0; break;}
					}
					if(is0 == fm.length()) {
						sb86.append(fm.substring(i));
						index = is0;
						break;
					}
					else {
						sb86.append(fm.substring(i,is0));
						i = is0 -1;
					}
				}
				else if (!is_numformat(c) && !is_datformat(c,fm.substring(i)) && !is_strformat(c))
				{
					if (c == 'e' || c == 'E' || c == 't' || c == 'T')
						throw new HpException(5, "Invalid procedure call");
					index = fmy.length()-1;
					sb86.append(c);
				}
				else {
					fmmm = fm;
					fm = fm.substring(i);
					indexof = fmy.indexOf(c);
					index = indexof;
					break;
				}
			}

			if(yes) {
				int no = 0;
				for(i = 0; i < index; i++) {     //format(12,"1997\11\8")
					char s = fmy.charAt(i);
					if(s == '\\')
					{
						sb86.insert(i-no, fmy.charAt(i+1));
						no++; i++;
					}
				}
    		}
			str1 = sb86.toString();
			if(str1.indexOf('[') != -1)
				throw new HpException(5, "Invalid procedure call");

			if(indexof != -1)
				fmy = fmy.substring(index);
			else {
				tmp = boolToStr(tmp);

				if (isNumOrDate(new VString(tmp))) {
					if ((new VString(tmp).dblValue()<0 || tmp.charAt(0) == '-') && for_mat.strValue().indexOf(';')==-1 && for_mat.strValue().indexOf('/')==-1)
						return new VString("-"+str1);
					else return new VString(str1);
				}
				else return exp;
			}

			int high = fmy.length();
			tmp = Unscien(tmp);

			/*** user-defined Number formats ***/

			if (is_numformat(c))
			{
				if(fm.indexOf('[') != -1)
					throw new HpException(5, "Invalid procedure call");
				boolean isFalse = false;
				tmp = boolToStr(tmp);
				if (tmp == "0")
					isFalse = true;

				if(isNumOrDate(new VString(tmp)) && !tmp.startsWith("-&"))
				{
					String subfm1 = null, subfm2 = null;
					StringBuffer sbb = new StringBuffer();

					char c100 = tmp.charAt(0);
					if (c100 == '+' || c100 == '-')
						tmp = tmp.substring(1);
					if(tmp.length()>1)
					{
						for(i=0; i<tmp.length(); )
						{
							if(tmp.charAt(i) == '0' && (tmp.charAt(i+1) == '0' || tmp.charAt(i+1) != '.'))
								i++;
							else break;
						}
						tmp = tmp.substring(i);
					}
					tmp = manyComma(tmp, fm);
					int cpp = tmp.indexOf(',');
					if (cpp != -1)
					{
						StringBuffer sb82 = new StringBuffer();
						for (int t=0; t<tmp.length(); t++)
							if(tmp.charAt(t)!=',')
								sb82.append(tmp.charAt(t));
						tmp = sb82.toString();
					}
					char c61 = ' ';
					num = fm.indexOf('e');
					if (num != -1)
						c61 = 'e';
					else
					{
						num = fm.indexOf('E');
						if (num != -1)
							c61 = 'E';
					}

					int count0 = 0;
					if(num != -1)
					{
						if(fm.substring(0,num).indexOf('0')==-1 && fm.substring(0,num).indexOf('#')==-1)
						{
							if(HpFuncMisc.ISNUMERIC(new VString(fm.substring(0,num))))
								return new VString(fmf);
							else
								throw new HpException(5, "Invalid procedure call");
						}
						if(num==(fm.length()-1))
							throw new HpException(5, "Invalid procedure call");
						else if(fm.substring(num).indexOf(',')!=-1)
							throw new HpException(5, "Invalid procedure call");

						c = fm.charAt(num+1);

						if(c != '-' && c != '+')
							throw new HpException(5, "Invalid procedure call");

						tmp = Per(tmp,fm.substring(0,num));
						for (n = 0; n < fm.substring(0,num).length();)
						{
							c = fm.substring(0,num).charAt(n);
							if(c == '0' || c == '#' || c == '.')
							{
								n++;
								sbb.append(c);
							}
							else n++;
						}
						subfm1 = sbb.toString();
						int sfp = subfm1.indexOf('.');
						if(sfp == -1)
							sfp = subfm1.length();
						StringBuffer ssb = new StringBuffer();
						for(n = 0; n < subfm1.length(); n++)
						{
							c = subfm1.charAt(n);
							if(c != '.')
								ssb.append(c);
						}
						subfm2 = ssb.toString();
						int tpp = tmp.indexOf('.');
						if(tpp == -1)
							tpp = tmp.length();
						StringBuffer sssb = new StringBuffer();
						for (n=0; n < tmp.length(); n++)
						{
							c = tmp.charAt(n);
							if(c != '.')
								sssb.append(c);
						}
						String subtmp = sssb.toString();
						for(n = 0; n<subtmp.length();n++ )
						{
							c = subtmp.charAt(n);
							if (c != '0')
							{
								m = n;
								break;
							}
						}
						tpp = tpp - m;
						if(subtmp.substring(m).length()>subfm2.length())
							sb.append(tzRound(subtmp.substring(m),subfm2.length()-1));
						else if(subtmp.substring(m).length()==subfm2.length())
							sb.append(subtmp.substring(m));
						else
						{
							sb.append(subtmp.substring(m));
							sb.append(subfm2.substring(subtmp.substring(m).length()));
						}
						if(subfm1.indexOf('.') != -1)
							sb.insert(sfp, '.');
						StringBuffer sbbb = new StringBuffer();
						for(n=0;n<fm.substring(0,num).length();n++)
							if(fm.charAt(n)!=',')
								sbbb.append(fm.charAt(n));
						String fm1 = sbbb.toString();
						for(n=fm1.length()-1; n>=0; n--)
						{
							c = fm1.charAt(n);
							if(c != '0' && c != '#' && c != '.')
								sb.insert(sb.length()-(fm1.length()-n)+1, c);
						}
						String tmp1 = sb.toString();
						String tmp123;
						if (m==0)
							tmp123 = tmp1;
						else
							tmp123 = subtmp.substring(0,m).concat(tmp1);
						int tpp2 = tmp123.indexOf('.');
						if(tpp2 == -1)
							tpp2 = tmp123.length();
						//if((cpp != -1 || isComma) && tmp1.length()!=0)
						//	tmp1 = comma(tmp1, null);

						sb = new StringBuffer(tmp1);
						int num2 = fmy.indexOf('E');
						int com = 1;
						int mod = 0;
						if(num2==-1) num2 = fmy.indexOf('e');
							String fmy1 = fmy.substring(0,num2);
						int high2 = num2;

						for(n=high2-1; n>=0; n--)
						{
							c = fmy1.charAt(n);
							char ch;
							if(n == 0)
							{
								if(c == '\\')
								{
									ch = fmy1.charAt(n+1);
									for(int z=sb.length()-(high2-n);z<sb.length();z++)
									{
										if(sb.charAt(z)==',') com++;
									}
									if(ch == '#')
										sb.insert(sb.length()-(high2-n-1)+com, ']');
									else
										sb.insert(sb.length()-(high2-n-1)+com, ch);
									com = 1;
								}
							}
							else
							{
								if(c == '\\')
								{
									ch = fmy1.charAt(n+1);
									for(int z = n-1; z>=0; z--)
									{
										if(fmy1.charAt(z)=='\\') mod++;
										else break;
									}
									if(mod % 2 == 0)
									{
										for(int z=sb.length()-(high2-n);z<sb.length();z++)
										{
											if(sb.charAt(z)==',') com++;
										}
										if(ch == '#')
											sb.insert(sb.length()-(high2-n-1)+com, ']');
										else
											sb.insert(sb.length()-(high2-n-1)+com, ch);
										com = 1;
										mod = 0; high2--;
									}
								}
							}
						}
						tmp1 = sb.toString();
						sb = new StringBuffer();
						for(n=0; n<tmp1.length(); n++)
						{
							char ch = tmp1.charAt(n);
							if(ch == '#')
								sb.append('0');
							else
							{
								if(ch == ']')
									sb.append('#');
								else
									sb.append(ch);
							}
						}
						String tmp1113 = sb.toString();
						if((cpp != -1 || isComma) && tmp1113.length()!=0)
							tmp1113 = comma(tmp1113, null);
						sb = new StringBuffer(tmp1113);
						sb.append(c61);
						if(new VString(tmp).dblValue() == 0)
							tpp = sfp;
						if(sfp > tpp) sb.append('-');
						else
						{
							if(fm.charAt(num+1) == '+')
							sb.append('+');
						}
						m = 0;
						for(n=num+2; n<fm.length(); )
						{
							if(fm.charAt(n) == '0')
							{
								m++; n++;
							}
							else if(fm.charAt(n) == '#')
								n++;
							else break;
						}
						if(m==0 || m==1)
							sb.append(Math.abs(tpp-sfp));
						else if(m==2)
							sb.append(Math.abs(tpp-sfp)<10?("0"+Math.abs(tpp-sfp)):(""+Math.abs(tpp-sfp)));
						else
						{
							if(Math.abs(tpp-sfp)<100 && Math.abs(tpp-sfp)>=10)
								sb.append("0"+Math.abs(tpp-sfp));
							else if(Math.abs(tpp-sfp)<10)
								sb.append("00"+Math.abs(tpp-sfp));
							else
								sb.append(Math.abs(tpp-sfp));
						}
						for(n=num2+2; n<fmy.length(); )
						{
							c=fmy.charAt(n);
							if(c == '\\')
							{
								sb.append(fmy.charAt(n+1));
								n = n+2;
							}
							else
							{
								if(c == '0' || c == '#')
									n++;
								else
								{
									if(c == 'e' || c == 'E')
									{
										if(fmy.charAt(n++) == ' ' || fmy.charAt(n++) != '-' || fmy.charAt(n++) != '+')
											throw new HpException(5, "Invalid procecure call");
										else
											sb.append(c);
									}
									else
										sb.append(c);
									n++;
								}
							}
						}
						str2 = sb.toString();
					}
					else
					{
						if(fm.indexOf('0') == -1 && fm.indexOf('#') == -1 && fm.indexOf('.') == -1 && HpFuncMisc.ISNUMERIC(for_mat))
						{
							if(c100 == '-') return new VString("-"+fmf);
							else return new VString(fmf);
						}
						tmp = Per(tmp,fm);
						for(n=0; n<fm.length(); n++)
							if(fm.charAt(n)!=',')
								sbb.append(fm.charAt(n));
						fm = sbb.toString();
						sbb = new StringBuffer();
						for(n=0; n<fm.length(); n++)
						{
							c = fm.charAt(n);
							if(c == '0' || c == '#' || c == '.')
								sbb.append(c);
						}
						subfm1 = sbb.toString();
						int sfp = subfm1.indexOf('.');
						if(sfp != -1)
						{
							int tpp = tmp.indexOf('.');
							if(tpp != -1)
							{
								if(sfp - tpp <= 0)
								{
									sb.append(tmp.substring(0,tpp));
									if(sfp-tpp<0)
									{
										sbb = new StringBuffer();
										for (n = 0; n < tpp-sfp; n++)

⌨️ 快捷键说明

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