741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// UnescapeMethods library |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2003 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
// Note that is not a part of "Xerver Free Web Server". |
741 |
10 Oct 06 |
olle |
30 |
|
1652 |
22 May 07 |
gregory |
31 |
/******************************************************************* |
1652 |
22 May 07 |
gregory |
* Everything below this line is part of the HTTPClient package * |
1652 |
22 May 07 |
gregory |
* URI.java, 0.3-3 06/05/2001 * |
1652 |
22 May 07 |
gregory |
* Copyright (C) 1996-2001 Ronald Tschal�r * |
1652 |
22 May 07 |
gregory |
35 |
* * |
1652 |
22 May 07 |
gregory |
* Contact: ronald@innovation.ch * |
1652 |
22 May 07 |
gregory |
37 |
* * |
1652 |
22 May 07 |
gregory |
* The HTTPClient's home page is located at: * |
1652 |
22 May 07 |
gregory |
* http://www.innovation.ch/java/HTTPClient/ * |
1652 |
22 May 07 |
gregory |
40 |
* * |
1652 |
22 May 07 |
gregory |
41 |
******************************************************************** |
1652 |
22 May 07 |
gregory |
42 |
* * |
1652 |
22 May 07 |
gregory |
* Source below has been modified by me, * |
1652 |
22 May 07 |
gregory |
* Omid Rouhani, author of Xerver. * |
1652 |
22 May 07 |
gregory |
45 |
* * |
1652 |
22 May 07 |
gregory |
* Note that this single file is released under LGPL, * |
1652 |
22 May 07 |
gregory |
* GNU Lesser General Public License, * |
1652 |
22 May 07 |
gregory |
* which is not the same license as the rest of * |
1652 |
22 May 07 |
gregory |
* Xerver is released under, GPL - GNU General Public License. * |
1652 |
22 May 07 |
gregory |
50 |
* * |
1652 |
22 May 07 |
gregory |
* This file is considered as a modified version of * |
1652 |
22 May 07 |
gregory |
* Ronald Tschal�r's HTTPClient package. * |
1652 |
22 May 07 |
gregory |
53 |
* * |
1652 |
22 May 07 |
gregory |
* Any copy of this single file shall be released under LGPL * |
1652 |
22 May 07 |
gregory |
* and shall not be mixed with the source of the rest of Xerver, * |
1652 |
22 May 07 |
gregory |
* which must be released under GPL. * |
1652 |
22 May 07 |
gregory |
57 |
* * |
1652 |
22 May 07 |
gregory |
58 |
*******************************************************************/ |
741 |
10 Oct 06 |
olle |
59 |
|
741 |
10 Oct 06 |
olle |
60 |
/******************************************************************************* |
741 |
10 Oct 06 |
olle |
61 |
|
1652 |
22 May 07 |
gregory |
GNU LESSER GENERAL PUBLIC LICENSE |
1652 |
22 May 07 |
gregory |
Version 2.1, February 1999 |
741 |
10 Oct 06 |
olle |
64 |
|
741 |
10 Oct 06 |
olle |
Copyright (C) 1991, 1999 Free Software Foundation, Inc. |
1652 |
22 May 07 |
gregory |
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
741 |
10 Oct 06 |
olle |
Everyone is permitted to copy and distribute verbatim copies |
741 |
10 Oct 06 |
olle |
of this license document, but changing it is not allowed. |
741 |
10 Oct 06 |
olle |
69 |
|
1652 |
22 May 07 |
gregory |
[This is the first released version of the Lesser GPL. It also counts |
741 |
10 Oct 06 |
olle |
as the successor of the GNU Library Public License, version 2, hence |
741 |
10 Oct 06 |
olle |
the version number 2.1.] |
741 |
10 Oct 06 |
olle |
73 |
|
1652 |
22 May 07 |
gregory |
Preamble |
741 |
10 Oct 06 |
olle |
75 |
|
1652 |
22 May 07 |
gregory |
The licenses for most software are designed to take away your |
1652 |
22 May 07 |
gregory |
freedom to share and change it. By contrast, the GNU General Public |
1652 |
22 May 07 |
gregory |
Licenses are intended to guarantee your freedom to share and change |
1652 |
22 May 07 |
gregory |
free software--to make sure the software is free for all its users. |
741 |
10 Oct 06 |
olle |
80 |
|
1652 |
22 May 07 |
gregory |
This license, the Lesser General Public License, applies to some |
1652 |
22 May 07 |
gregory |
specially designated software packages--typically libraries--of the |
1652 |
22 May 07 |
gregory |
Free Software Foundation and other authors who decide to use it. You |
1652 |
22 May 07 |
gregory |
can use it too, but we suggest you first think carefully about whether |
1652 |
22 May 07 |
gregory |
this license or the ordinary General Public License is the better |
1652 |
22 May 07 |
gregory |
strategy to use in any particular case, based on the explanations below. |
741 |
10 Oct 06 |
olle |
87 |
|
1652 |
22 May 07 |
gregory |
When we speak of free software, we are referring to freedom of use, |
1652 |
22 May 07 |
gregory |
not price. Our General Public Licenses are designed to make sure that |
1652 |
22 May 07 |
gregory |
you have the freedom to distribute copies of free software (and charge |
1652 |
22 May 07 |
gregory |
for this service if you wish); that you receive source code or can get |
1652 |
22 May 07 |
gregory |
it if you want it; that you can change the software and use pieces of |
1652 |
22 May 07 |
gregory |
it in new free programs; and that you are informed that you can do |
1652 |
22 May 07 |
gregory |
these things. |
741 |
10 Oct 06 |
olle |
95 |
|
1652 |
22 May 07 |
gregory |
To protect your rights, we need to make restrictions that forbid |
1652 |
22 May 07 |
gregory |
distributors to deny you these rights or to ask you to surrender these |
1652 |
22 May 07 |
gregory |
rights. These restrictions translate to certain responsibilities for |
1652 |
22 May 07 |
gregory |
you if you distribute copies of the library or if you modify it. |
741 |
10 Oct 06 |
olle |
100 |
|
1652 |
22 May 07 |
gregory |
For example, if you distribute copies of the library, whether gratis |
1652 |
22 May 07 |
gregory |
or for a fee, you must give the recipients all the rights that we gave |
1652 |
22 May 07 |
gregory |
you. You must make sure that they, too, receive or can get the source |
1652 |
22 May 07 |
gregory |
code. If you link other code with the library, you must provide |
1652 |
22 May 07 |
gregory |
complete object files to the recipients, so that they can relink them |
1652 |
22 May 07 |
gregory |
with the library after making changes to the library and recompiling |
1652 |
22 May 07 |
gregory |
it. And you must show them these terms so they know their rights. |
741 |
10 Oct 06 |
olle |
108 |
|
1652 |
22 May 07 |
gregory |
We protect your rights with a two-step method: (1) we copyright the |
1652 |
22 May 07 |
gregory |
library, and (2) we offer you this license, which gives you legal |
1652 |
22 May 07 |
gregory |
permission to copy, distribute and/or modify the library. |
741 |
10 Oct 06 |
olle |
112 |
|
1652 |
22 May 07 |
gregory |
To protect each distributor, we want to make it very clear that |
1652 |
22 May 07 |
gregory |
there is no warranty for the free library. Also, if the library is |
1652 |
22 May 07 |
gregory |
modified by someone else and passed on, the recipients should know |
1652 |
22 May 07 |
gregory |
that what they have is not the original version, so that the original |
1652 |
22 May 07 |
gregory |
author's reputation will not be affected by problems that might be |
1652 |
22 May 07 |
gregory |
introduced by others. |
741 |
10 Oct 06 |
olle |
119 |
|
1652 |
22 May 07 |
gregory |
Finally, software patents pose a constant threat to the existence of |
1652 |
22 May 07 |
gregory |
any free program. We wish to make sure that a company cannot |
1652 |
22 May 07 |
gregory |
effectively restrict the users of a free program by obtaining a |
1652 |
22 May 07 |
gregory |
restrictive license from a patent holder. Therefore, we insist that |
1652 |
22 May 07 |
gregory |
any patent license obtained for a version of the library must be |
1652 |
22 May 07 |
gregory |
consistent with the full freedom of use specified in this license. |
741 |
10 Oct 06 |
olle |
126 |
|
1652 |
22 May 07 |
gregory |
Most GNU software, including some libraries, is covered by the |
1652 |
22 May 07 |
gregory |
ordinary GNU General Public License. This license, the GNU Lesser |
1652 |
22 May 07 |
gregory |
General Public License, applies to certain designated libraries, and |
1652 |
22 May 07 |
gregory |
is quite different from the ordinary General Public License. We use |
1652 |
22 May 07 |
gregory |
this license for certain libraries in order to permit linking those |
1652 |
22 May 07 |
gregory |
libraries into non-free programs. |
741 |
10 Oct 06 |
olle |
133 |
|
1652 |
22 May 07 |
gregory |
When a program is linked with a library, whether statically or using |
1652 |
22 May 07 |
gregory |
a shared library, the combination of the two is legally speaking a |
1652 |
22 May 07 |
gregory |
combined work, a derivative of the original library. The ordinary |
1652 |
22 May 07 |
gregory |
General Public License therefore permits such linking only if the |
1652 |
22 May 07 |
gregory |
entire combination fits its criteria of freedom. The Lesser General |
1652 |
22 May 07 |
gregory |
Public License permits more lax criteria for linking other code with |
1652 |
22 May 07 |
gregory |
the library. |
741 |
10 Oct 06 |
olle |
141 |
|
1652 |
22 May 07 |
gregory |
We call this license the "Lesser" General Public License because it |
1652 |
22 May 07 |
gregory |
does Less to protect the user's freedom than the ordinary General |
1652 |
22 May 07 |
gregory |
Public License. It also provides other free software developers Less |
1652 |
22 May 07 |
gregory |
of an advantage over competing non-free programs. These disadvantages |
1652 |
22 May 07 |
gregory |
are the reason we use the ordinary General Public License for many |
1652 |
22 May 07 |
gregory |
libraries. However, the Lesser license provides advantages in certain |
1652 |
22 May 07 |
gregory |
special circumstances. |
741 |
10 Oct 06 |
olle |
149 |
|
1652 |
22 May 07 |
gregory |
For example, on rare occasions, there may be a special need to |
1652 |
22 May 07 |
gregory |
encourage the widest possible use of a certain library, so that it becomes |
1652 |
22 May 07 |
gregory |
a de-facto standard. To achieve this, non-free programs must be |
1652 |
22 May 07 |
gregory |
allowed to use the library. A more frequent case is that a free |
1652 |
22 May 07 |
gregory |
library does the same job as widely used non-free libraries. In this |
1652 |
22 May 07 |
gregory |
case, there is little to gain by limiting the free library to free |
1652 |
22 May 07 |
gregory |
software only, so we use the Lesser General Public License. |
741 |
10 Oct 06 |
olle |
157 |
|
1652 |
22 May 07 |
gregory |
In other cases, permission to use a particular library in non-free |
1652 |
22 May 07 |
gregory |
programs enables a greater number of people to use a large body of |
1652 |
22 May 07 |
gregory |
free software. For example, permission to use the GNU C Library in |
1652 |
22 May 07 |
gregory |
non-free programs enables many more people to use the whole GNU |
1652 |
22 May 07 |
gregory |
operating system, as well as its variant, the GNU/Linux operating |
1652 |
22 May 07 |
gregory |
system. |
741 |
10 Oct 06 |
olle |
164 |
|
1652 |
22 May 07 |
gregory |
Although the Lesser General Public License is Less protective of the |
1652 |
22 May 07 |
gregory |
users' freedom, it does ensure that the user of a program that is |
1652 |
22 May 07 |
gregory |
linked with the Library has the freedom and the wherewithal to run |
1652 |
22 May 07 |
gregory |
that program using a modified version of the Library. |
741 |
10 Oct 06 |
olle |
169 |
|
1652 |
22 May 07 |
gregory |
The precise terms and conditions for copying, distribution and |
1652 |
22 May 07 |
gregory |
modification follow. Pay close attention to the difference between a |
1652 |
22 May 07 |
gregory |
"work based on the library" and a "work that uses the library". The |
1652 |
22 May 07 |
gregory |
former contains code derived from the library, whereas the latter must |
1652 |
22 May 07 |
gregory |
be combined with the library in order to run. |
741 |
10 Oct 06 |
olle |
175 |
|
1652 |
22 May 07 |
gregory |
GNU LESSER GENERAL PUBLIC LICENSE |
1652 |
22 May 07 |
gregory |
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
741 |
10 Oct 06 |
olle |
178 |
|
1652 |
22 May 07 |
gregory |
0. This License Agreement applies to any software library or other |
1652 |
22 May 07 |
gregory |
program which contains a notice placed by the copyright holder or |
1652 |
22 May 07 |
gregory |
other authorized party saying it may be distributed under the terms of |
1652 |
22 May 07 |
gregory |
this Lesser General Public License (also called "this License"). |
1652 |
22 May 07 |
gregory |
Each licensee is addressed as "you". |
741 |
10 Oct 06 |
olle |
184 |
|
1652 |
22 May 07 |
gregory |
A "library" means a collection of software functions and/or data |
1652 |
22 May 07 |
gregory |
prepared so as to be conveniently linked with application programs |
1652 |
22 May 07 |
gregory |
(which use some of those functions and data) to form executables. |
741 |
10 Oct 06 |
olle |
188 |
|
1652 |
22 May 07 |
gregory |
The "Library", below, refers to any such software library or work |
1652 |
22 May 07 |
gregory |
which has been distributed under these terms. A "work based on the |
1652 |
22 May 07 |
gregory |
Library" means either the Library or any derivative work under |
1652 |
22 May 07 |
gregory |
copyright law: that is to say, a work containing the Library or a |
1652 |
22 May 07 |
gregory |
portion of it, either verbatim or with modifications and/or translated |
1652 |
22 May 07 |
gregory |
straightforwardly into another language. (Hereinafter, translation is |
1652 |
22 May 07 |
gregory |
included without limitation in the term "modification".) |
741 |
10 Oct 06 |
olle |
196 |
|
1652 |
22 May 07 |
gregory |
"Source code" for a work means the preferred form of the work for |
1652 |
22 May 07 |
gregory |
making modifications to it. For a library, complete source code means |
1652 |
22 May 07 |
gregory |
all the source code for all modules it contains, plus any associated |
1652 |
22 May 07 |
gregory |
interface definition files, plus the scripts used to control compilation |
1652 |
22 May 07 |
gregory |
and installation of the library. |
741 |
10 Oct 06 |
olle |
202 |
|
1652 |
22 May 07 |
gregory |
Activities other than copying, distribution and modification are not |
1652 |
22 May 07 |
gregory |
covered by this License; they are outside its scope. The act of |
1652 |
22 May 07 |
gregory |
running a program using the Library is not restricted, and output from |
1652 |
22 May 07 |
gregory |
such a program is covered only if its contents constitute a work based |
1652 |
22 May 07 |
gregory |
on the Library (independent of the use of the Library in a tool for |
1652 |
22 May 07 |
gregory |
writing it). Whether that is true depends on what the Library does |
1652 |
22 May 07 |
gregory |
and what the program that uses the Library does. |
741 |
10 Oct 06 |
olle |
210 |
|
1652 |
22 May 07 |
gregory |
1. You may copy and distribute verbatim copies of the Library's |
1652 |
22 May 07 |
gregory |
complete source code as you receive it, in any medium, provided that |
1652 |
22 May 07 |
gregory |
you conspicuously and appropriately publish on each copy an |
1652 |
22 May 07 |
gregory |
appropriate copyright notice and disclaimer of warranty; keep intact |
1652 |
22 May 07 |
gregory |
all the notices that refer to this License and to the absence of any |
1652 |
22 May 07 |
gregory |
warranty; and distribute a copy of this License along with the |
1652 |
22 May 07 |
gregory |
Library. |
741 |
10 Oct 06 |
olle |
218 |
|
1652 |
22 May 07 |
gregory |
You may charge a fee for the physical act of transferring a copy, |
1652 |
22 May 07 |
gregory |
and you may at your option offer warranty protection in exchange for a |
1652 |
22 May 07 |
gregory |
fee. |
741 |
10 Oct 06 |
olle |
222 |
|
1652 |
22 May 07 |
gregory |
2. You may modify your copy or copies of the Library or any portion |
1652 |
22 May 07 |
gregory |
of it, thus forming a work based on the Library, and copy and |
1652 |
22 May 07 |
gregory |
distribute such modifications or work under the terms of Section 1 |
1652 |
22 May 07 |
gregory |
above, provided that you also meet all of these conditions: |
741 |
10 Oct 06 |
olle |
227 |
|
1652 |
22 May 07 |
gregory |
a) The modified work must itself be a software library. |
741 |
10 Oct 06 |
olle |
229 |
|
1652 |
22 May 07 |
gregory |
b) You must cause the files modified to carry prominent notices |
1652 |
22 May 07 |
gregory |
stating that you changed the files and the date of any change. |
741 |
10 Oct 06 |
olle |
232 |
|
1652 |
22 May 07 |
gregory |
c) You must cause the whole of the work to be licensed at no |
1652 |
22 May 07 |
gregory |
charge to all third parties under the terms of this License. |
741 |
10 Oct 06 |
olle |
235 |
|
1652 |
22 May 07 |
gregory |
d) If a facility in the modified Library refers to a function or a |
1652 |
22 May 07 |
gregory |
table of data to be supplied by an application program that uses |
1652 |
22 May 07 |
gregory |
the facility, other than as an argument passed when the facility |
1652 |
22 May 07 |
gregory |
is invoked, then you must make a good faith effort to ensure that, |
1652 |
22 May 07 |
gregory |
in the event an application does not supply such function or |
1652 |
22 May 07 |
gregory |
table, the facility still operates, and performs whatever part of |
1652 |
22 May 07 |
gregory |
its purpose remains meaningful. |
741 |
10 Oct 06 |
olle |
243 |
|
1652 |
22 May 07 |
gregory |
(For example, a function in a library to compute square roots has |
1652 |
22 May 07 |
gregory |
a purpose that is entirely well-defined independent of the |
1652 |
22 May 07 |
gregory |
application. Therefore, Subsection 2d requires that any |
1652 |
22 May 07 |
gregory |
application-supplied function or table used by this function must |
1652 |
22 May 07 |
gregory |
be optional: if the application does not supply it, the square |
1652 |
22 May 07 |
gregory |
root function must still compute square roots.) |
741 |
10 Oct 06 |
olle |
250 |
|
1652 |
22 May 07 |
gregory |
These requirements apply to the modified work as a whole. If |
1652 |
22 May 07 |
gregory |
identifiable sections of that work are not derived from the Library, |
1652 |
22 May 07 |
gregory |
and can be reasonably considered independent and separate works in |
1652 |
22 May 07 |
gregory |
themselves, then this License, and its terms, do not apply to those |
1652 |
22 May 07 |
gregory |
sections when you distribute them as separate works. But when you |
1652 |
22 May 07 |
gregory |
distribute the same sections as part of a whole which is a work based |
1652 |
22 May 07 |
gregory |
on the Library, the distribution of the whole must be on the terms of |
1652 |
22 May 07 |
gregory |
this License, whose permissions for other licensees extend to the |
1652 |
22 May 07 |
gregory |
entire whole, and thus to each and every part regardless of who wrote |
1652 |
22 May 07 |
gregory |
it. |
741 |
10 Oct 06 |
olle |
261 |
|
1652 |
22 May 07 |
gregory |
Thus, it is not the intent of this section to claim rights or contest |
1652 |
22 May 07 |
gregory |
your rights to work written entirely by you; rather, the intent is to |
1652 |
22 May 07 |
gregory |
exercise the right to control the distribution of derivative or |
1652 |
22 May 07 |
gregory |
collective works based on the Library. |
741 |
10 Oct 06 |
olle |
266 |
|
1652 |
22 May 07 |
gregory |
In addition, mere aggregation of another work not based on the Library |
1652 |
22 May 07 |
gregory |
with the Library (or with a work based on the Library) on a volume of |
1652 |
22 May 07 |
gregory |
a storage or distribution medium does not bring the other work under |
1652 |
22 May 07 |
gregory |
the scope of this License. |
741 |
10 Oct 06 |
olle |
271 |
|
1652 |
22 May 07 |
gregory |
3. You may opt to apply the terms of the ordinary GNU General Public |
1652 |
22 May 07 |
gregory |
License instead of this License to a given copy of the Library. To do |
1652 |
22 May 07 |
gregory |
this, you must alter all the notices that refer to this License, so |
1652 |
22 May 07 |
gregory |
that they refer to the ordinary GNU General Public License, version 2, |
1652 |
22 May 07 |
gregory |
instead of to this License. (If a newer version than version 2 of the |
1652 |
22 May 07 |
gregory |
ordinary GNU General Public License has appeared, then you can specify |
1652 |
22 May 07 |
gregory |
that version instead if you wish.) Do not make any other change in |
1652 |
22 May 07 |
gregory |
these notices. |
741 |
10 Oct 06 |
olle |
280 |
|
1652 |
22 May 07 |
gregory |
Once this change is made in a given copy, it is irreversible for |
1652 |
22 May 07 |
gregory |
that copy, so the ordinary GNU General Public License applies to all |
1652 |
22 May 07 |
gregory |
subsequent copies and derivative works made from that copy. |
741 |
10 Oct 06 |
olle |
284 |
|
1652 |
22 May 07 |
gregory |
This option is useful when you wish to copy part of the code of |
1652 |
22 May 07 |
gregory |
the Library into a program that is not a library. |
741 |
10 Oct 06 |
olle |
287 |
|
1652 |
22 May 07 |
gregory |
4. You may copy and distribute the Library (or a portion or |
1652 |
22 May 07 |
gregory |
derivative of it, under Section 2) in object code or executable form |
1652 |
22 May 07 |
gregory |
under the terms of Sections 1 and 2 above provided that you accompany |
1652 |
22 May 07 |
gregory |
it with the complete corresponding machine-readable source code, which |
1652 |
22 May 07 |
gregory |
must be distributed under the terms of Sections 1 and 2 above on a |
1652 |
22 May 07 |
gregory |
medium customarily used for software interchange. |
741 |
10 Oct 06 |
olle |
294 |
|
1652 |
22 May 07 |
gregory |
If distribution of object code is made by offering access to copy |
1652 |
22 May 07 |
gregory |
from a designated place, then offering equivalent access to copy the |
1652 |
22 May 07 |
gregory |
source code from the same place satisfies the requirement to |
1652 |
22 May 07 |
gregory |
distribute the source code, even though third parties are not |
1652 |
22 May 07 |
gregory |
compelled to copy the source along with the object code. |
741 |
10 Oct 06 |
olle |
300 |
|
1652 |
22 May 07 |
gregory |
5. A program that contains no derivative of any portion of the |
1652 |
22 May 07 |
gregory |
Library, but is designed to work with the Library by being compiled or |
1652 |
22 May 07 |
gregory |
linked with it, is called a "work that uses the Library". Such a |
1652 |
22 May 07 |
gregory |
work, in isolation, is not a derivative work of the Library, and |
1652 |
22 May 07 |
gregory |
therefore falls outside the scope of this License. |
741 |
10 Oct 06 |
olle |
306 |
|
1652 |
22 May 07 |
gregory |
However, linking a "work that uses the Library" with the Library |
1652 |
22 May 07 |
gregory |
creates an executable that is a derivative of the Library (because it |
1652 |
22 May 07 |
gregory |
contains portions of the Library), rather than a "work that uses the |
1652 |
22 May 07 |
gregory |
library". The executable is therefore covered by this License. |
1652 |
22 May 07 |
gregory |
Section 6 states terms for distribution of such executables. |
741 |
10 Oct 06 |
olle |
312 |
|
1652 |
22 May 07 |
gregory |
When a "work that uses the Library" uses material from a header file |
1652 |
22 May 07 |
gregory |
that is part of the Library, the object code for the work may be a |
1652 |
22 May 07 |
gregory |
derivative work of the Library even though the source code is not. |
1652 |
22 May 07 |
gregory |
Whether this is true is especially significant if the work can be |
1652 |
22 May 07 |
gregory |
linked without the Library, or if the work is itself a library. The |
1652 |
22 May 07 |
gregory |
threshold for this to be true is not precisely defined by law. |
741 |
10 Oct 06 |
olle |
319 |
|
1652 |
22 May 07 |
gregory |
If such an object file uses only numerical parameters, data |
1652 |
22 May 07 |
gregory |
structure layouts and accessors, and small macros and small inline |
1652 |
22 May 07 |
gregory |
functions (ten lines or less in length), then the use of the object |
1652 |
22 May 07 |
gregory |
file is unrestricted, regardless of whether it is legally a derivative |
1652 |
22 May 07 |
gregory |
work. (Executables containing this object code plus portions of the |
1652 |
22 May 07 |
gregory |
Library will still fall under Section 6.) |
741 |
10 Oct 06 |
olle |
326 |
|
1652 |
22 May 07 |
gregory |
Otherwise, if the work is a derivative of the Library, you may |
1652 |
22 May 07 |
gregory |
distribute the object code for the work under the terms of Section 6. |
1652 |
22 May 07 |
gregory |
Any executables containing that work also fall under Section 6, |
1652 |
22 May 07 |
gregory |
whether or not they are linked directly with the Library itself. |
741 |
10 Oct 06 |
olle |
331 |
|
1652 |
22 May 07 |
gregory |
6. As an exception to the Sections above, you may also combine or |
1652 |
22 May 07 |
gregory |
link a "work that uses the Library" with the Library to produce a |
1652 |
22 May 07 |
gregory |
work containing portions of the Library, and distribute that work |
1652 |
22 May 07 |
gregory |
under terms of your choice, provided that the terms permit |
1652 |
22 May 07 |
gregory |
modification of the work for the customer's own use and reverse |
1652 |
22 May 07 |
gregory |
engineering for debugging such modifications. |
741 |
10 Oct 06 |
olle |
338 |
|
1652 |
22 May 07 |
gregory |
You must give prominent notice with each copy of the work that the |
1652 |
22 May 07 |
gregory |
Library is used in it and that the Library and its use are covered by |
1652 |
22 May 07 |
gregory |
this License. You must supply a copy of this License. If the work |
1652 |
22 May 07 |
gregory |
during execution displays copyright notices, you must include the |
1652 |
22 May 07 |
gregory |
copyright notice for the Library among them, as well as a reference |
1652 |
22 May 07 |
gregory |
directing the user to the copy of this License. Also, you must do one |
1652 |
22 May 07 |
gregory |
of these things: |
741 |
10 Oct 06 |
olle |
346 |
|
1652 |
22 May 07 |
gregory |
a) Accompany the work with the complete corresponding |
1652 |
22 May 07 |
gregory |
machine-readable source code for the Library including whatever |
1652 |
22 May 07 |
gregory |
changes were used in the work (which must be distributed under |
1652 |
22 May 07 |
gregory |
Sections 1 and 2 above); and, if the work is an executable linked |
1652 |
22 May 07 |
gregory |
with the Library, with the complete machine-readable "work that |
1652 |
22 May 07 |
gregory |
uses the Library", as object code and/or source code, so that the |
1652 |
22 May 07 |
gregory |
user can modify the Library and then relink to produce a modified |
1652 |
22 May 07 |
gregory |
executable containing the modified Library. (It is understood |
1652 |
22 May 07 |
gregory |
that the user who changes the contents of definitions files in the |
1652 |
22 May 07 |
gregory |
Library will not necessarily be able to recompile the application |
1652 |
22 May 07 |
gregory |
to use the modified definitions.) |
741 |
10 Oct 06 |
olle |
358 |
|
1652 |
22 May 07 |
gregory |
b) Use a suitable shared library mechanism for linking with the |
1652 |
22 May 07 |
gregory |
Library. A suitable mechanism is one that (1) uses at run time a |
1652 |
22 May 07 |
gregory |
copy of the library already present on the user's computer system, |
1652 |
22 May 07 |
gregory |
rather than copying library functions into the executable, and (2) |
1652 |
22 May 07 |
gregory |
will operate properly with a modified version of the library, if |
1652 |
22 May 07 |
gregory |
the user installs one, as long as the modified version is |
1652 |
22 May 07 |
gregory |
interface-compatible with the version that the work was made with. |
741 |
10 Oct 06 |
olle |
366 |
|
1652 |
22 May 07 |
gregory |
c) Accompany the work with a written offer, valid for at |
1652 |
22 May 07 |
gregory |
least three years, to give the same user the materials |
1652 |
22 May 07 |
gregory |
specified in Subsection 6a, above, for a charge no more |
1652 |
22 May 07 |
gregory |
than the cost of performing this distribution. |
741 |
10 Oct 06 |
olle |
371 |
|
1652 |
22 May 07 |
gregory |
d) If distribution of the work is made by offering access to copy |
1652 |
22 May 07 |
gregory |
from a designated place, offer equivalent access to copy the above |
1652 |
22 May 07 |
gregory |
specified materials from the same place. |
741 |
10 Oct 06 |
olle |
375 |
|
1652 |
22 May 07 |
gregory |
e) Verify that the user has already received a copy of these |
1652 |
22 May 07 |
gregory |
materials or that you have already sent this user a copy. |
741 |
10 Oct 06 |
olle |
378 |
|
1652 |
22 May 07 |
gregory |
For an executable, the required form of the "work that uses the |
1652 |
22 May 07 |
gregory |
Library" must include any data and utility programs needed for |
1652 |
22 May 07 |
gregory |
reproducing the executable from it. However, as a special exception, |
1652 |
22 May 07 |
gregory |
the materials to be distributed need not include anything that is |
1652 |
22 May 07 |
gregory |
normally distributed (in either source or binary form) with the major |
1652 |
22 May 07 |
gregory |
components (compiler, kernel, and so on) of the operating system on |
1652 |
22 May 07 |
gregory |
which the executable runs, unless that component itself accompanies |
1652 |
22 May 07 |
gregory |
the executable. |
741 |
10 Oct 06 |
olle |
387 |
|
1652 |
22 May 07 |
gregory |
It may happen that this requirement contradicts the license |
1652 |
22 May 07 |
gregory |
restrictions of other proprietary libraries that do not normally |
1652 |
22 May 07 |
gregory |
accompany the operating system. Such a contradiction means you cannot |
1652 |
22 May 07 |
gregory |
use both them and the Library together in an executable that you |
1652 |
22 May 07 |
gregory |
distribute. |
741 |
10 Oct 06 |
olle |
393 |
|
1652 |
22 May 07 |
gregory |
7. You may place library facilities that are a work based on the |
1652 |
22 May 07 |
gregory |
Library side-by-side in a single library together with other library |
1652 |
22 May 07 |
gregory |
facilities not covered by this License, and distribute such a combined |
1652 |
22 May 07 |
gregory |
library, provided that the separate distribution of the work based on |
1652 |
22 May 07 |
gregory |
the Library and of the other library facilities is otherwise |
1652 |
22 May 07 |
gregory |
permitted, and provided that you do these two things: |
741 |
10 Oct 06 |
olle |
400 |
|
1652 |
22 May 07 |
gregory |
a) Accompany the combined library with a copy of the same work |
1652 |
22 May 07 |
gregory |
based on the Library, uncombined with any other library |
1652 |
22 May 07 |
gregory |
facilities. This must be distributed under the terms of the |
1652 |
22 May 07 |
gregory |
Sections above. |
741 |
10 Oct 06 |
olle |
405 |
|
1652 |
22 May 07 |
gregory |
b) Give prominent notice with the combined library of the fact |
1652 |
22 May 07 |
gregory |
that part of it is a work based on the Library, and explaining |
1652 |
22 May 07 |
gregory |
where to find the accompanying uncombined form of the same work. |
741 |
10 Oct 06 |
olle |
409 |
|
1652 |
22 May 07 |
gregory |
8. You may not copy, modify, sublicense, link with, or distribute |
1652 |
22 May 07 |
gregory |
the Library except as expressly provided under this License. Any |
1652 |
22 May 07 |
gregory |
attempt otherwise to copy, modify, sublicense, link with, or |
1652 |
22 May 07 |
gregory |
distribute the Library is void, and will automatically terminate your |
1652 |
22 May 07 |
gregory |
rights under this License. However, parties who have received copies, |
1652 |
22 May 07 |
gregory |
or rights, from you under this License will not have their licenses |
1652 |
22 May 07 |
gregory |
terminated so long as such parties remain in full compliance. |
741 |
10 Oct 06 |
olle |
417 |
|
1652 |
22 May 07 |
gregory |
9. You are not required to accept this License, since you have not |
1652 |
22 May 07 |
gregory |
signed it. However, nothing else grants you permission to modify or |
1652 |
22 May 07 |
gregory |
distribute the Library or its derivative works. These actions are |
1652 |
22 May 07 |
gregory |
prohibited by law if you do not accept this License. Therefore, by |
1652 |
22 May 07 |
gregory |
modifying or distributing the Library (or any work based on the |
1652 |
22 May 07 |
gregory |
Library), you indicate your acceptance of this License to do so, and |
1652 |
22 May 07 |
gregory |
all its terms and conditions for copying, distributing or modifying |
1652 |
22 May 07 |
gregory |
the Library or works based on it. |
741 |
10 Oct 06 |
olle |
426 |
|
1652 |
22 May 07 |
gregory |
10. Each time you redistribute the Library (or any work based on the |
1652 |
22 May 07 |
gregory |
Library), the recipient automatically receives a license from the |
1652 |
22 May 07 |
gregory |
original licensor to copy, distribute, link with or modify the Library |
1652 |
22 May 07 |
gregory |
subject to these terms and conditions. You may not impose any further |
1652 |
22 May 07 |
gregory |
restrictions on the recipients' exercise of the rights granted herein. |
1652 |
22 May 07 |
gregory |
You are not responsible for enforcing compliance by third parties with |
1652 |
22 May 07 |
gregory |
this License. |
741 |
10 Oct 06 |
olle |
434 |
|
1652 |
22 May 07 |
gregory |
11. If, as a consequence of a court judgment or allegation of patent |
1652 |
22 May 07 |
gregory |
infringement or for any other reason (not limited to patent issues), |
1652 |
22 May 07 |
gregory |
conditions are imposed on you (whether by court order, agreement or |
1652 |
22 May 07 |
gregory |
otherwise) that contradict the conditions of this License, they do not |
1652 |
22 May 07 |
gregory |
excuse you from the conditions of this License. If you cannot |
1652 |
22 May 07 |
gregory |
distribute so as to satisfy simultaneously your obligations under this |
1652 |
22 May 07 |
gregory |
License and any other pertinent obligations, then as a consequence you |
1652 |
22 May 07 |
gregory |
may not distribute the Library at all. For example, if a patent |
1652 |
22 May 07 |
gregory |
license would not permit royalty-free redistribution of the Library by |
1652 |
22 May 07 |
gregory |
all those who receive copies directly or indirectly through you, then |
1652 |
22 May 07 |
gregory |
the only way you could satisfy both it and this License would be to |
1652 |
22 May 07 |
gregory |
refrain entirely from distribution of the Library. |
741 |
10 Oct 06 |
olle |
447 |
|
1652 |
22 May 07 |
gregory |
If any portion of this section is held invalid or unenforceable under any |
1652 |
22 May 07 |
gregory |
particular circumstance, the balance of the section is intended to apply, |
1652 |
22 May 07 |
gregory |
and the section as a whole is intended to apply in other circumstances. |
741 |
10 Oct 06 |
olle |
451 |
|
1652 |
22 May 07 |
gregory |
It is not the purpose of this section to induce you to infringe any |
1652 |
22 May 07 |
gregory |
patents or other property right claims or to contest validity of any |
1652 |
22 May 07 |
gregory |
such claims; this section has the sole purpose of protecting the |
1652 |
22 May 07 |
gregory |
integrity of the free software distribution system which is |
1652 |
22 May 07 |
gregory |
implemented by public license practices. Many people have made |
1652 |
22 May 07 |
gregory |
generous contributions to the wide range of software distributed |
1652 |
22 May 07 |
gregory |
through that system in reliance on consistent application of that |
1652 |
22 May 07 |
gregory |
system; it is up to the author/donor to decide if he or she is willing |
1652 |
22 May 07 |
gregory |
to distribute software through any other system and a licensee cannot |
1652 |
22 May 07 |
gregory |
impose that choice. |
741 |
10 Oct 06 |
olle |
462 |
|
1652 |
22 May 07 |
gregory |
This section is intended to make thoroughly clear what is believed to |
1652 |
22 May 07 |
gregory |
be a consequence of the rest of this License. |
741 |
10 Oct 06 |
olle |
465 |
|
1652 |
22 May 07 |
gregory |
12. If the distribution and/or use of the Library is restricted in |
1652 |
22 May 07 |
gregory |
certain countries either by patents or by copyrighted interfaces, the |
1652 |
22 May 07 |
gregory |
original copyright holder who places the Library under this License may add |
1652 |
22 May 07 |
gregory |
an explicit geographical distribution limitation excluding those countries, |
1652 |
22 May 07 |
gregory |
so that distribution is permitted only in or among countries not thus |
1652 |
22 May 07 |
gregory |
excluded. In such case, this License incorporates the limitation as if |
1652 |
22 May 07 |
gregory |
written in the body of this License. |
741 |
10 Oct 06 |
olle |
473 |
|
1652 |
22 May 07 |
gregory |
13. The Free Software Foundation may publish revised and/or new |
1652 |
22 May 07 |
gregory |
versions of the Lesser General Public License from time to time. |
1652 |
22 May 07 |
gregory |
Such new versions will be similar in spirit to the present version, |
1652 |
22 May 07 |
gregory |
but may differ in detail to address new problems or concerns. |
741 |
10 Oct 06 |
olle |
478 |
|
1652 |
22 May 07 |
gregory |
Each version is given a distinguishing version number. If the Library |
1652 |
22 May 07 |
gregory |
specifies a version number of this License which applies to it and |
1652 |
22 May 07 |
gregory |
"any later version", you have the option of following the terms and |
1652 |
22 May 07 |
gregory |
conditions either of that version or of any later version published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation. If the Library does not specify a |
1652 |
22 May 07 |
gregory |
license version number, you may choose any version ever published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation. |
741 |
10 Oct 06 |
olle |
486 |
|
1652 |
22 May 07 |
gregory |
14. If you wish to incorporate parts of the Library into other free |
1652 |
22 May 07 |
gregory |
programs whose distribution conditions are incompatible with these, |
1652 |
22 May 07 |
gregory |
write to the author to ask for permission. For software which is |
1652 |
22 May 07 |
gregory |
copyrighted by the Free Software Foundation, write to the Free |
1652 |
22 May 07 |
gregory |
Software Foundation; we sometimes make exceptions for this. Our |
1652 |
22 May 07 |
gregory |
decision will be guided by the two goals of preserving the free status |
1652 |
22 May 07 |
gregory |
of all derivatives of our free software and of promoting the sharing |
1652 |
22 May 07 |
gregory |
and reuse of software generally. |
741 |
10 Oct 06 |
olle |
495 |
|
1652 |
22 May 07 |
gregory |
NO WARRANTY |
741 |
10 Oct 06 |
olle |
497 |
|
1652 |
22 May 07 |
gregory |
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO |
1652 |
22 May 07 |
gregory |
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. |
1652 |
22 May 07 |
gregory |
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR |
1652 |
22 May 07 |
gregory |
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY |
1652 |
22 May 07 |
gregory |
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
1652 |
22 May 07 |
gregory |
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
1652 |
22 May 07 |
gregory |
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
1652 |
22 May 07 |
gregory |
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME |
1652 |
22 May 07 |
gregory |
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. |
741 |
10 Oct 06 |
olle |
507 |
|
1652 |
22 May 07 |
gregory |
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN |
1652 |
22 May 07 |
gregory |
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY |
1652 |
22 May 07 |
gregory |
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU |
1652 |
22 May 07 |
gregory |
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR |
1652 |
22 May 07 |
gregory |
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
1652 |
22 May 07 |
gregory |
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
1652 |
22 May 07 |
gregory |
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
1652 |
22 May 07 |
gregory |
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
1652 |
22 May 07 |
gregory |
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
1652 |
22 May 07 |
gregory |
DAMAGES. |
741 |
10 Oct 06 |
olle |
518 |
|
1652 |
22 May 07 |
gregory |
END OF TERMS AND CONDITIONS |
741 |
10 Oct 06 |
olle |
520 |
|
1652 |
22 May 07 |
gregory |
How to Apply These Terms to Your New Libraries |
741 |
10 Oct 06 |
olle |
522 |
|
1652 |
22 May 07 |
gregory |
If you develop a new library, and you want it to be of the greatest |
1652 |
22 May 07 |
gregory |
possible use to the public, we recommend making it free software that |
1652 |
22 May 07 |
gregory |
everyone can redistribute and change. You can do so by permitting |
1652 |
22 May 07 |
gregory |
redistribution under these terms (or, alternatively, under the terms of the |
1652 |
22 May 07 |
gregory |
ordinary General Public License). |
741 |
10 Oct 06 |
olle |
528 |
|
1652 |
22 May 07 |
gregory |
To apply these terms, attach the following notices to the library. It is |
1652 |
22 May 07 |
gregory |
safest to attach them to the start of each source file to most effectively |
1652 |
22 May 07 |
gregory |
convey the exclusion of warranty; and each file should have at least the |
1652 |
22 May 07 |
gregory |
"copyright" line and a pointer to where the full notice is found. |
741 |
10 Oct 06 |
olle |
533 |
|
1652 |
22 May 07 |
gregory |
<one line to give the library's name and a brief idea of what it does.> |
1652 |
22 May 07 |
gregory |
Copyright (C) <year> <name of author> |
741 |
10 Oct 06 |
olle |
536 |
|
1652 |
22 May 07 |
gregory |
This library is free software; you can redistribute it and/or |
1652 |
22 May 07 |
gregory |
modify it under the terms of the GNU Lesser General Public |
1652 |
22 May 07 |
gregory |
License as published by the Free Software Foundation; either |
1652 |
22 May 07 |
gregory |
version 2.1 of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
541 |
|
1652 |
22 May 07 |
gregory |
This library is distributed in the hope that it will be useful, |
1652 |
22 May 07 |
gregory |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
Lesser General Public License for more details. |
741 |
10 Oct 06 |
olle |
546 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU Lesser General Public |
1652 |
22 May 07 |
gregory |
License along with this library; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
741 |
10 Oct 06 |
olle |
550 |
|
1652 |
22 May 07 |
gregory |
Also add information on how to contact you by electronic and paper mail. |
741 |
10 Oct 06 |
olle |
552 |
|
1652 |
22 May 07 |
gregory |
You should also get your employer (if you work as a programmer) or your |
1652 |
22 May 07 |
gregory |
school, if any, to sign a "copyright disclaimer" for the library, if |
1652 |
22 May 07 |
gregory |
necessary. Here is a sample; alter the names: |
741 |
10 Oct 06 |
olle |
556 |
|
1652 |
22 May 07 |
gregory |
Yoyodyne, Inc., hereby disclaims all copyright interest in the |
1652 |
22 May 07 |
gregory |
library `Frob' (a library for tweaking knobs) written by James Random Hacker. |
741 |
10 Oct 06 |
olle |
559 |
|
1652 |
22 May 07 |
gregory |
<signature of Ty Coon>, 1 April 1990 |
1652 |
22 May 07 |
gregory |
Ty Coon, President of Vice |
741 |
10 Oct 06 |
olle |
562 |
|
1652 |
22 May 07 |
gregory |
That's all there is to it! |
741 |
10 Oct 06 |
olle |
564 |
|
741 |
10 Oct 06 |
olle |
565 |
|
1652 |
22 May 07 |
gregory |
566 |
*******************************************************************************/ |
741 |
10 Oct 06 |
olle |
567 |
|
1652 |
22 May 07 |
gregory |
568 |
package se.lu.thep.coreftpd.common; |
741 |
10 Oct 06 |
olle |
569 |
|
741 |
10 Oct 06 |
olle |
570 |
import java.util.BitSet; |
741 |
10 Oct 06 |
olle |
571 |
|
741 |
10 Oct 06 |
olle |
572 |
/** |
1652 |
22 May 07 |
gregory |
573 |
* |
1652 |
22 May 07 |
gregory |
* <B>About this class:</B> <BR> |
741 |
10 Oct 06 |
olle |
* Contains a few very useful methods for unescaping <CODE>String</CODE>s. |
1652 |
22 May 07 |
gregory |
576 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @version 1.0 |
741 |
10 Oct 06 |
olle |
579 |
*/ |
741 |
10 Oct 06 |
olle |
580 |
|
1652 |
22 May 07 |
gregory |
581 |
final public class UnescapeMethods { |
741 |
10 Oct 06 |
olle |
582 |
|
1652 |
22 May 07 |
gregory |
583 |
private static final char[] hex = { '0', '1', '2', '3', '4', '5', '6', '7', |
1652 |
22 May 07 |
gregory |
584 |
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; |
741 |
10 Oct 06 |
olle |
585 |
|
1652 |
22 May 07 |
gregory |
586 |
private static final int enc(char[] out, int pos, int c) { |
1652 |
22 May 07 |
gregory |
587 |
out[pos++] = '%'; |
1652 |
22 May 07 |
gregory |
588 |
out[pos++] = hex[(c >> 4) & 0xf]; |
1652 |
22 May 07 |
gregory |
589 |
out[pos++] = hex[c & 0xf]; |
1652 |
22 May 07 |
gregory |
590 |
return pos; |
1652 |
22 May 07 |
gregory |
591 |
} |
741 |
10 Oct 06 |
olle |
592 |
|
1652 |
22 May 07 |
gregory |
// REMOVED: * @exception ParseException if the two digits following a `%' |
1652 |
22 May 07 |
gregory |
// are |
1652 |
22 May 07 |
gregory |
// * not a valid hex number |
1652 |
22 May 07 |
gregory |
596 |
/** |
1652 |
22 May 07 |
gregory |
* Unescape escaped characters (i.e. %xx) except reserved ones. |
1652 |
22 May 07 |
gregory |
598 |
* |
1652 |
22 May 07 |
gregory |
* @param str |
1652 |
22 May 07 |
gregory |
* the string to unescape |
1652 |
22 May 07 |
gregory |
* @param reserved |
1652 |
22 May 07 |
gregory |
* the characters which may not be unescaped, or null |
1652 |
22 May 07 |
gregory |
* @return the unescaped string |
1652 |
22 May 07 |
gregory |
604 |
*/ |
741 |
10 Oct 06 |
olle |
605 |
|
1652 |
22 May 07 |
gregory |
606 |
public static final String unescape(String str, BitSet reserved) |
1652 |
22 May 07 |
gregory |
// throws ParseException |
1652 |
22 May 07 |
gregory |
608 |
{ |
1652 |
22 May 07 |
gregory |
609 |
if (str == null || str.indexOf('%') == -1) |
1652 |
22 May 07 |
gregory |
610 |
return str; // an optimization |
741 |
10 Oct 06 |
olle |
611 |
|
1652 |
22 May 07 |
gregory |
612 |
char[] buf = str.toCharArray(); |
1652 |
22 May 07 |
gregory |
613 |
char[] res = new char[buf.length]; |
741 |
10 Oct 06 |
olle |
614 |
|
1652 |
22 May 07 |
gregory |
615 |
char[] utf = new char[4]; |
1652 |
22 May 07 |
gregory |
616 |
int utf_idx = 0, utf_len = -1; |
1652 |
22 May 07 |
gregory |
617 |
int didx = 0; |
1652 |
22 May 07 |
gregory |
618 |
for (int sidx = 0; sidx < buf.length; sidx++) { |
1652 |
22 May 07 |
gregory |
619 |
if (buf[sidx] == '%') { |
1652 |
22 May 07 |
gregory |
620 |
int ch; |
1652 |
22 May 07 |
gregory |
621 |
try { |
1652 |
22 May 07 |
gregory |
622 |
if (sidx + 3 > buf.length) |
1652 |
22 May 07 |
gregory |
623 |
throw new NumberFormatException(); |
1652 |
22 May 07 |
gregory |
624 |
ch = Integer |
1652 |
22 May 07 |
gregory |
625 |
.parseInt(str.substring(sidx + 1, sidx + 3), 16); |
1652 |
22 May 07 |
gregory |
626 |
if (ch < 0) |
1652 |
22 May 07 |
gregory |
627 |
throw new NumberFormatException(); |
1652 |
22 May 07 |
gregory |
628 |
sidx += 2; |
1652 |
22 May 07 |
gregory |
629 |
} catch (NumberFormatException e) { |
1652 |
22 May 07 |
gregory |
630 |
/* |
1652 |
22 May 07 |
gregory |
* Hmm, people not reading specs again, so we just ignore |
1652 |
22 May 07 |
gregory |
* it... throw new ParseException(str.substring(sidx,sidx+3) + " |
1652 |
22 May 07 |
gregory |
* is an invalid code"); |
1652 |
22 May 07 |
gregory |
634 |
*/ |
1652 |
22 May 07 |
gregory |
635 |
ch = buf[sidx]; |
1652 |
22 May 07 |
gregory |
636 |
} |
741 |
10 Oct 06 |
olle |
637 |
|
1652 |
22 May 07 |
gregory |
// check if we're working on a utf-char |
1652 |
22 May 07 |
gregory |
639 |
if (utf_len > 0) { |
1652 |
22 May 07 |
gregory |
640 |
if ((ch & 0xC0) != 0x80) // oops, we misinterpreted |
1652 |
22 May 07 |
gregory |
641 |
{ |
1652 |
22 May 07 |
gregory |
642 |
didx = copyBuf(utf, utf_idx, ch, res, didx, reserved, |
1652 |
22 May 07 |
gregory |
643 |
false); |
1652 |
22 May 07 |
gregory |
644 |
utf_len = -1; |
1652 |
22 May 07 |
gregory |
645 |
} else if (utf_idx == utf_len - 1) // end-of-char |
1652 |
22 May 07 |
gregory |
646 |
{ |
1652 |
22 May 07 |
gregory |
647 |
if ((utf[0] & 0xE0) == 0xC0) |
1652 |
22 May 07 |
gregory |
648 |
ch = (utf[0] & 0x1F) << 6 | (ch & 0x3F); |
1652 |
22 May 07 |
gregory |
649 |
else if ((utf[0] & 0xF0) == 0xE0) |
1652 |
22 May 07 |
gregory |
650 |
ch = (utf[0] & 0x0F) << 12 | (utf[1] & 0x3F) << 6 |
1652 |
22 May 07 |
gregory |
651 |
| (ch & 0x3F); |
1652 |
22 May 07 |
gregory |
652 |
else |
1652 |
22 May 07 |
gregory |
653 |
ch = (utf[0] & 0x07) << 18 | (utf[1] & 0x3F) << 12 |
1652 |
22 May 07 |
gregory |
654 |
| (utf[2] & 0x3F) << 6 | (ch & 0x3F); |
1652 |
22 May 07 |
gregory |
655 |
if (reserved != null && reserved.get(ch)) |
1652 |
22 May 07 |
gregory |
656 |
didx = copyBuf(utf, utf_idx, ch, res, didx, null, |
1652 |
22 May 07 |
gregory |
657 |
true); |
1652 |
22 May 07 |
gregory |
658 |
else if (utf_len < 4) |
1652 |
22 May 07 |
gregory |
659 |
res[didx++] = (char) ch; |
1652 |
22 May 07 |
gregory |
660 |
else { |
1652 |
22 May 07 |
gregory |
661 |
ch -= 0x10000; |
1652 |
22 May 07 |
gregory |
662 |
res[didx++] = (char) ((ch >> 10) | 0xD800); |
1652 |
22 May 07 |
gregory |
663 |
res[didx++] = (char) ((ch & 0x03FF) | 0xDC00); |
1652 |
22 May 07 |
gregory |
664 |
} |
1652 |
22 May 07 |
gregory |
665 |
utf_len = -1; |
1652 |
22 May 07 |
gregory |
666 |
} else |
1652 |
22 May 07 |
gregory |
// continue |
1652 |
22 May 07 |
gregory |
668 |
utf[utf_idx++] = (char) ch; |
1652 |
22 May 07 |
gregory |
669 |
} |
1652 |
22 May 07 |
gregory |
// check if this is the start of a utf-char |
1652 |
22 May 07 |
gregory |
671 |
else if ((ch & 0xE0) == 0xC0 || (ch & 0xF0) == 0xE0 |
1652 |
22 May 07 |
gregory |
672 |
|| (ch & 0xF8) == 0xF0) { |
1652 |
22 May 07 |
gregory |
673 |
if ((ch & 0xE0) == 0xC0) |
1652 |
22 May 07 |
gregory |
674 |
utf_len = 2; |
1652 |
22 May 07 |
gregory |
675 |
else if ((ch & 0xF0) == 0xE0) |
1652 |
22 May 07 |
gregory |
676 |
utf_len = 3; |
1652 |
22 May 07 |
gregory |
677 |
else |
1652 |
22 May 07 |
gregory |
678 |
utf_len = 4; |
1652 |
22 May 07 |
gregory |
679 |
utf[0] = (char) ch; |
1652 |
22 May 07 |
gregory |
680 |
utf_idx = 1; |
1652 |
22 May 07 |
gregory |
681 |
} |
1652 |
22 May 07 |
gregory |
// leave reserved alone |
1652 |
22 May 07 |
gregory |
683 |
else if (reserved != null && reserved.get(ch)) { |
1652 |
22 May 07 |
gregory |
684 |
res[didx++] = buf[sidx]; |
1652 |
22 May 07 |
gregory |
685 |
sidx -= 2; |
1652 |
22 May 07 |
gregory |
686 |
} |
1652 |
22 May 07 |
gregory |
// just use the decoded version |
1652 |
22 May 07 |
gregory |
688 |
else |
1652 |
22 May 07 |
gregory |
689 |
res[didx++] = (char) ch; |
1652 |
22 May 07 |
gregory |
690 |
} else if (utf_len > 0) // oops, we misinterpreted |
1652 |
22 May 07 |
gregory |
691 |
{ |
1652 |
22 May 07 |
gregory |
692 |
didx = copyBuf(utf, utf_idx, buf[sidx], res, didx, reserved, |
1652 |
22 May 07 |
gregory |
693 |
false); |
1652 |
22 May 07 |
gregory |
694 |
utf_len = -1; |
1652 |
22 May 07 |
gregory |
695 |
} else |
1652 |
22 May 07 |
gregory |
696 |
res[didx++] = buf[sidx]; |
1652 |
22 May 07 |
gregory |
697 |
} |
1652 |
22 May 07 |
gregory |
698 |
if (utf_len > 0) // oops, we misinterpreted |
1652 |
22 May 07 |
gregory |
699 |
didx = copyBuf(utf, utf_idx, -1, res, didx, reserved, false); |
741 |
10 Oct 06 |
olle |
700 |
|
1652 |
22 May 07 |
gregory |
701 |
return new String(res, 0, didx); |
1652 |
22 May 07 |
gregory |
702 |
} |
741 |
10 Oct 06 |
olle |
703 |
|
1652 |
22 May 07 |
gregory |
704 |
private static final int copyBuf(char[] utf, int utf_idx, int ch, |
1652 |
22 May 07 |
gregory |
705 |
char[] res, int didx, BitSet reserved, boolean escapeAll) { |
1652 |
22 May 07 |
gregory |
706 |
if (ch >= 0) |
1652 |
22 May 07 |
gregory |
707 |
utf[utf_idx++] = (char) ch; |
741 |
10 Oct 06 |
olle |
708 |
|
1652 |
22 May 07 |
gregory |
709 |
for (int idx = 0; idx < utf_idx; idx++) { |
1652 |
22 May 07 |
gregory |
710 |
if (reserved != null && reserved.get(utf[idx]) || escapeAll) |
1652 |
22 May 07 |
gregory |
711 |
didx = enc(res, didx, utf[idx]); |
741 |
10 Oct 06 |
olle |
712 |
else |
1652 |
22 May 07 |
gregory |
713 |
res[didx++] = utf[idx]; |
741 |
10 Oct 06 |
olle |
714 |
} |
741 |
10 Oct 06 |
olle |
715 |
|
1652 |
22 May 07 |
gregory |
716 |
return didx; |
741 |
10 Oct 06 |
olle |
717 |
} |
741 |
10 Oct 06 |
olle |
718 |
|
1652 |
22 May 07 |
gregory |
719 |
/** |
1652 |
22 May 07 |
gregory |
* Unescape escaped characters (i.e. %xx). If a ParseException would be |
1652 |
22 May 07 |
gregory |
* thrown then just return the original string. |
1652 |
22 May 07 |
gregory |
722 |
* |
1652 |
22 May 07 |
gregory |
* @param str |
1652 |
22 May 07 |
gregory |
* the string to unescape |
1652 |
22 May 07 |
gregory |
* @param reserved |
1652 |
22 May 07 |
gregory |
* the characters which may not be unescaped, or null |
1652 |
22 May 07 |
gregory |
* @return the unescaped string, or the original string if unescaping would |
1652 |
22 May 07 |
gregory |
* throw a ParseException |
1652 |
22 May 07 |
gregory |
* @see #unescape(java.lang.String, java.util.BitSet) |
1652 |
22 May 07 |
gregory |
730 |
*/ |
1652 |
22 May 07 |
gregory |
731 |
/* |
1652 |
22 May 07 |
gregory |
* public static final String unescapeNoPE(String str, BitSet reserved) { // |
1652 |
22 May 07 |
gregory |
* try { return unescape(str, reserved); } // catch (ParseException pe) // { |
1652 |
22 May 07 |
gregory |
* System.out.println("OJ H�R BLEV DET VISST ERROR!");return str; } } |
1652 |
22 May 07 |
gregory |
735 |
*/ |
741 |
10 Oct 06 |
olle |
736 |
|
1652 |
22 May 07 |
gregory |
737 |
/** |
1652 |
22 May 07 |
gregory |
* Escape any character not in the given character class. Characters greater |
1652 |
22 May 07 |
gregory |
* 255 are always escaped according to ??? . |
1652 |
22 May 07 |
gregory |
740 |
* |
1652 |
22 May 07 |
gregory |
* @param elem |
1652 |
22 May 07 |
gregory |
* the string to escape |
1652 |
22 May 07 |
gregory |
* @param allowed_char |
1652 |
22 May 07 |
gregory |
* the BitSet of all allowed characters |
1652 |
22 May 07 |
gregory |
* @param utf8 |
1652 |
22 May 07 |
gregory |
* if true, will first UTF-8 encode unallowed characters |
1652 |
22 May 07 |
gregory |
* @return the string with all characters not in allowed_char escaped |
1652 |
22 May 07 |
gregory |
748 |
*/ |
741 |
10 Oct 06 |
olle |
749 |
|
1652 |
22 May 07 |
gregory |
750 |
/* |
1652 |
22 May 07 |
gregory |
* We temporary remove this..... public static String escape(String elem, |
1652 |
22 May 07 |
gregory |
* BitSet allowed_char, boolean utf8) { if (elem==null) return null; else |
1652 |
22 May 07 |
gregory |
* return new String(escape(elem.toCharArray(), allowed_char, utf8)); } |
1652 |
22 May 07 |
gregory |
754 |
*/ |
741 |
10 Oct 06 |
olle |
755 |
|
1652 |
22 May 07 |
gregory |
756 |
/** |
1652 |
22 May 07 |
gregory |
* Escape any character not in the given character class. Characters greater |
1652 |
22 May 07 |
gregory |
* 255 are always escaped according to ??? . |
1652 |
22 May 07 |
gregory |
759 |
* |
1652 |
22 May 07 |
gregory |
* @param elem |
1652 |
22 May 07 |
gregory |
* the array of characters to escape |
1652 |
22 May 07 |
gregory |
* @param allowed_char |
1652 |
22 May 07 |
gregory |
* the BitSet of all allowed characters |
1652 |
22 May 07 |
gregory |
* @param utf8 |
1652 |
22 May 07 |
gregory |
* if true, will first UTF-8 encode unallowed characters |
1652 |
22 May 07 |
gregory |
* @return the elem array with all characters not in allowed_char escaped |
1652 |
22 May 07 |
gregory |
767 |
*/ |
741 |
10 Oct 06 |
olle |
768 |
|
1652 |
22 May 07 |
gregory |
// We temporary remove this..... |
1652 |
22 May 07 |
gregory |
770 |
// |
1652 |
22 May 07 |
gregory |
// public static char[] escape(char[] elem, BitSet allowed_char, boolean |
1652 |
22 May 07 |
gregory |
// utf8) |
1652 |
22 May 07 |
gregory |
773 |
// { |
1652 |
22 May 07 |
gregory |
// int cnt=0; |
1652 |
22 May 07 |
gregory |
// for (int idx=0; idx<elem.length; idx++) |
1652 |
22 May 07 |
gregory |
776 |
// { |
1652 |
22 May 07 |
gregory |
// if (!allowed_char.get(elem[idx])) |
1652 |
22 May 07 |
gregory |
778 |
// { |
1652 |
22 May 07 |
gregory |
// cnt += 2; |
1652 |
22 May 07 |
gregory |
// if (utf8) |
1652 |
22 May 07 |
gregory |
781 |
// { |
1652 |
22 May 07 |
gregory |
// if (elem[idx] >= 0x0080) |
1652 |
22 May 07 |
gregory |
// cnt += 3; |
1652 |
22 May 07 |
gregory |
// if (elem[idx] >= 0x00800) |
1652 |
22 May 07 |
gregory |
// cnt += 3; |
1652 |
22 May 07 |
gregory |
// if ((elem[idx] & 0xFC00) == 0xD800 && idx+1 < elem.length && |
1652 |
22 May 07 |
gregory |
// (elem[idx+1] & 0xFC00) == 0xDC00) |
1652 |
22 May 07 |
gregory |
// cnt -= 6; |
1652 |
22 May 07 |
gregory |
789 |
// } |
1652 |
22 May 07 |
gregory |
790 |
// } |
1652 |
22 May 07 |
gregory |
791 |
// } |
1652 |
22 May 07 |
gregory |
792 |
// |
1652 |
22 May 07 |
gregory |
// if (cnt == 0) return elem; |
1652 |
22 May 07 |
gregory |
794 |
// |
1652 |
22 May 07 |
gregory |
// char[] tmp = new char[elem.length + cnt]; |
1652 |
22 May 07 |
gregory |
// for (int idx=0, pos=0; idx<elem.length; idx++) |
1652 |
22 May 07 |
gregory |
797 |
// { |
1652 |
22 May 07 |
gregory |
// char c = elem[idx]; |
1652 |
22 May 07 |
gregory |
// if (allowed_char.get(c)) |
1652 |
22 May 07 |
gregory |
// tmp[pos++] = c; |
1652 |
22 May 07 |
gregory |
// else if (utf8) |
1652 |
22 May 07 |
gregory |
802 |
// { |
1652 |
22 May 07 |
gregory |
// /* We're UTF-8 encoding the chars first, as recommended in |
1652 |
22 May 07 |
gregory |
// * the HTML 4.0 specification: |
1652 |
22 May 07 |
gregory |
// * http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1 |
1652 |
22 May 07 |
gregory |
// * Note that this doesn't change things for ASCII chars |
1652 |
22 May 07 |
gregory |
807 |
// */ |
1652 |
22 May 07 |
gregory |
// if (c <= 0x007F) |
1652 |
22 May 07 |
gregory |
809 |
// { |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, c); |
1652 |
22 May 07 |
gregory |
811 |
// } |
1652 |
22 May 07 |
gregory |
// else if (c <= 0x07FF) |
1652 |
22 May 07 |
gregory |
813 |
// { |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0xC0 | ((c >> 6) & 0x1F)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((c >> 0) & 0x3F)); |
1652 |
22 May 07 |
gregory |
816 |
// } |
1652 |
22 May 07 |
gregory |
// else if (!((c & 0xFC00) == 0xD800 && idx+1 < elem.length && |
1652 |
22 May 07 |
gregory |
// (elem[idx+1] & 0xFC00) == 0xDC00)) |
1652 |
22 May 07 |
gregory |
819 |
// { |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0xE0 | ((c >> 12) & 0x0F)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((c >> 6) & 0x3F)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((c >> 0) & 0x3F)); |
1652 |
22 May 07 |
gregory |
823 |
// } |
1652 |
22 May 07 |
gregory |
// else |
1652 |
22 May 07 |
gregory |
825 |
// { |
1652 |
22 May 07 |
gregory |
// int ch = ((c & 0x03FF) << 10) | (elem[++idx] & 0x03FF); |
1652 |
22 May 07 |
gregory |
// ch += 0x10000; |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0xF0 | ((ch >> 18) & 0x07)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((ch >> 12) & 0x3F)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((ch >> 6) & 0x3F)); |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, 0x80 | ((ch >> 0) & 0x3F)); |
1652 |
22 May 07 |
gregory |
832 |
// } |
1652 |
22 May 07 |
gregory |
833 |
// } |
1652 |
22 May 07 |
gregory |
// else |
1652 |
22 May 07 |
gregory |
// pos = enc(tmp, pos, c); |
1652 |
22 May 07 |
gregory |
836 |
// } |
1652 |
22 May 07 |
gregory |
837 |
// |
1652 |
22 May 07 |
gregory |
// return tmp; |
1652 |
22 May 07 |
gregory |
839 |
// } |
741 |
10 Oct 06 |
olle |
840 |
} |