00001 /*----------------------------------------------------------------------------*/ 00002 /* */ 00003 /* Copyright (c) 2004-2009 William Data Systems Ltd. and Geoff Stevens. */ 00004 /* All rights reserved. */ 00005 /* */ 00006 /* This program and the accompanying materials are made available under */ 00007 /* the terms of the Common Public License v1.0 which accompanies this */ 00008 /* distribution. A copy is also available at the following address: */ 00009 /* http://www.opensource.org/licenses/cpl1.0.php */ 00010 /* */ 00011 /* Redistribution and use in source and binary forms, with or without */ 00012 /* modification, are permitted provided that the following conditions */ 00013 /* are met: */ 00014 /* */ 00015 /* Redistributions of source code must retain the above copyright */ 00016 /* notice, this list of conditions and the following disclaimer. */ 00017 /* */ 00018 /* Redistributions in binary form must reproduce the above copyright */ 00019 /* notice, this list of conditions and the following disclaimer in the */ 00020 /* documentation and/or other materials provided with the distribution. */ 00021 /* */ 00022 /* Neither the name or trademarks of William Data Systems nor the names */ 00023 /* of its contributors may be used to endorse or promote products */ 00024 /* derived from this software without specific prior written permission. */ 00025 /* */ 00026 /* DISCLAIMER */ 00027 /* */ 00028 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ 00029 /* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */ 00030 /* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR */ 00031 /* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */ 00032 /* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */ 00033 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00034 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */ 00035 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY */ 00036 /* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00037 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ 00038 /* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00039 /* */ 00040 /*----------------------------------------------------------------------------*/ 00041 -- representation of a decorated source document 00042 00043 -- The source document (an array of text lines) is converted into an array of 00044 -- .lightlines. 00045 -- Any string (markup, etc.) can be inserted at any point in the document 00046 -- at low cost, then the whole source document reconstituted into an array of 00047 -- text lines with all the decorations inserted 00048 ::CLASS colourable PUBLIC 00049 ::ATTRIBUTE lines -- lightlines 00050 00051 ::METHOD init 00052 use arg text 00053 00054 self~lines = .queue~new 00055 00056 do i over text 00057 if i = '' 00058 then i = ' ' 00059 self~lines~queue(.lightline~new(i)) 00060 end 00061 00062 ::METHOD line 00063 use arg index 00064 return lines[index] 00065 00066 ::METHOD toQueue 00067 q = .queue~new 00068 do i over lines 00069 q~queue(i~toString) 00070 end 00071 return q 00072 00073 ::METHOD fcaddpre 00074 use arg fc, index, toadd 00075 00076 parse value fc~index2vector(index) with line col 00077 self~lines[line]~addpre(col, toadd) 00078 00079 ::METHOD fcaddpost 00080 use arg fc, index, toadd 00081 parse value fc~index2vector(index) with line col 00082 self~lines[line]~addpost(col, toadd) 00083 00084 ::METHOD addpre 00085 use arg line, col, toadd 00086 self~lines[line]~addpre(col, toadd) 00087 00088 ::METHOD addpost 00089 use arg line, col, toadd 00090 self~lines[line]~addpost(col, toadd) 00091 00092 00093 -- representation of a source line 00094 -- insertions can be made nefore or after any character position 00095 -- the complete edited line can then be reconstituted 00096 ::CLASS lightline PUBLIC 00097 00098 ::ATTRIBUTE pre -- directory of insertions pre character 00099 ::ATTRIBUTE post -- directory of insertions post character 00100 ::ATTRIBUTE src -- the source line 00101 ::ATTRIBUTE srclen -- length of source line 00102 00103 -- @param src - the source line 00104 ::METHOD init 00105 use arg src 00106 self~src = src 00107 self~srclen = src~length 00108 self~pre = .directory~new 00109 self~post = .directory~new 00110 00111 -- add a string before a character position 00112 -- @param index - 1index of character 00113 -- @param toadd - string to add 00114 ::METHOD addpre 00115 use arg index, toadd 00116 00117 if self~pre~hasindex(index) 00118 then do 00119 self~pre[index] = toadd || self~pre[index] 00120 end 00121 else do 00122 self~pre[index] = toadd 00123 end 00124 00125 -- add a string after a character position 00126 -- @param index - 1index of character 00127 -- @param toadd - string to add 00128 ::METHOD addpost 00129 use arg index, toadd 00130 00131 if self~post~hasindex(index) 00132 then do 00133 self~post[index] = self~post[index] || toadd 00134 end 00135 else do 00136 self~post[index] = toadd 00137 end 00138 00139 -- return the string with any additions inserted 00140 -- the original string is cleaned for html use 00141 -- @return string 00142 ::METHOD tohtmlstring 00143 copysrc = self~src 00144 line = '' 00145 do j = 1 to self~srclen 00146 parse var copysrc 1 c 2 copysrc 00147 00148 select 00149 when c = '<' 00150 then c = '<' 00151 when c = '>' 00152 then c = '>' 00153 when c = '&' 00154 then c = '&' 00155 otherwise nop 00156 end 00157 00158 pre = '' 00159 post = '' 00160 00161 if self~pre~hasindex(j) 00162 then pre = self~pre[j] 00163 00164 if self~post~hasindex(j) 00165 then post = self~post[j] 00166 00167 line = line || pre || c || post 00168 end 00169 return line 00170 00171 -- return the string with any additions inserted 00172 -- @return string 00173 ::METHOD tostring 00174 copysrc = self~src 00175 line = '' 00176 do j = 1 to self~srclen 00177 parse var copysrc 1 c 2 copysrc 00178 pre = '' 00179 post = '' 00180 00181 if self~pre~hasindex(j) 00182 then pre = self~pre[j] 00183 00184 if self~post~hasindex(j) 00185 then post = self~post[j] 00186 00187 line = line || pre || c || post 00188 end 00189 return line 00190
|
Generated on 31 Aug 2010 05:20:02 for RexxLiterate by
![]() |