* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-24 23:29:39 -04:00
|
|
|
|
# -*- coding: euc-jp -*-
|
2003-07-31 16:52:40 -04:00
|
|
|
|
#
|
|
|
|
|
# Text Search widget demo (called by 'widget')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# textLoadFile --
|
|
|
|
|
# This method below loads a file into a text widget, discarding
|
|
|
|
|
# the previous contents of the widget. Tags for the old widget are
|
|
|
|
|
# not affected, however.
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
|
# w - The window into which to load the file. Must be a
|
|
|
|
|
# text widget.
|
|
|
|
|
# file - The name of the file to load. Must be readable.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
def textLoadFile(w,file)
|
|
|
|
|
w.delete('1.0', 'end')
|
|
|
|
|
f = open(file, 'r')
|
|
|
|
|
while(!f.eof?)
|
|
|
|
|
w.insert('end', f.read(1000))
|
|
|
|
|
end
|
|
|
|
|
f.close
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# textSearch --
|
|
|
|
|
# Search for all instances of a given string in a text widget and
|
|
|
|
|
# apply a given tag to each instance found.
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
|
# w - The window in which to search. Must be a text widget.
|
|
|
|
|
# string - The string to search for. The search is done using
|
|
|
|
|
# exact matching only; no special characters.
|
|
|
|
|
# tag - Tag to apply to each instance of a matching string.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
def textSearch(w, string, tag)
|
|
|
|
|
tag.remove('0.0', 'end')
|
|
|
|
|
return if string == ""
|
|
|
|
|
cur = '1.0'
|
|
|
|
|
loop {
|
|
|
|
|
cur, len = w.search_with_length(string, cur, 'end')
|
|
|
|
|
break if cur == ""
|
|
|
|
|
tag.add(cur, "#{cur} + #{len} char")
|
|
|
|
|
cur = w.index("#{cur} + #{len} char")
|
|
|
|
|
}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# textToggle --
|
|
|
|
|
# This method is invoked repeatedly to invoke two commands at
|
|
|
|
|
# periodic intervals. It normally reschedules itself after each
|
|
|
|
|
# execution but if an error occurs (e.g. because the window was
|
|
|
|
|
# deleted) then it doesn't reschedule itself.
|
|
|
|
|
#
|
|
|
|
|
# Arguments:
|
2004-10-11 00:51:21 -04:00
|
|
|
|
# cmd1 - Command to execute when method is called.
|
|
|
|
|
# sleep1 - Ms to sleep after executing cmd1 before executing cmd2.
|
|
|
|
|
# cmd2 - Command to execute in the *next* invocation of this method.
|
|
|
|
|
# sleep2 - Ms to sleep after executing cmd2 before executing cmd1 again.
|
2003-07-31 16:52:40 -04:00
|
|
|
|
|
|
|
|
|
def textToggle(cmd1,sleep1,cmd2,sleep2)
|
|
|
|
|
sleep_list = [sleep2, sleep1]
|
|
|
|
|
TkAfter.new(proc{sleep = sleep_list.shift; sleep_list.push(sleep); sleep},
|
2004-10-11 00:51:21 -04:00
|
|
|
|
-1, cmd1, cmd2).start(sleep1)
|
2003-07-31 16:52:40 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# toplevel widget <20><>¸<EFBFBD>ߤ<EFBFBD><DFA4><EFBFBD><EFBFBD>к<EFBFBD><D0BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
if defined?($search_demo) && $search_demo
|
|
|
|
|
$search_demo.destroy
|
|
|
|
|
$search_demo = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# demo <20>Ѥ<EFBFBD> toplevel widget <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
$search_demo = TkToplevel.new {|w|
|
|
|
|
|
title("Text Demonstration - Search and Highlight")
|
|
|
|
|
iconname("search")
|
|
|
|
|
positionWindow(w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# frame <20><><EFBFBD><EFBFBD>
|
|
|
|
|
$search_buttons = TkFrame.new($search_demo) {|frame|
|
|
|
|
|
TkButton.new(frame) {
|
2004-05-01 12:09:54 -04:00
|
|
|
|
#text 'λ<><CEBB>'
|
|
|
|
|
text '<27>Ĥ<EFBFBD><C4A4><EFBFBD>'
|
2003-07-31 16:52:40 -04:00
|
|
|
|
command proc{
|
|
|
|
|
tmppath = $search_demo
|
|
|
|
|
$search_demo = nil
|
|
|
|
|
tmppath.destroy
|
|
|
|
|
}
|
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes')
|
|
|
|
|
|
|
|
|
|
TkButton.new(frame) {
|
|
|
|
|
text '<27><><EFBFBD><EFBFBD><EFBFBD>ɻ<EFBFBD><C9BB><EFBFBD>'
|
|
|
|
|
command proc{showCode 'search'}
|
|
|
|
|
}.pack('side'=>'left', 'expand'=>'yes')
|
|
|
|
|
}
|
|
|
|
|
$search_buttons.pack('side'=>'bottom', 'fill'=>'x', 'pady'=>'2m')
|
|
|
|
|
|
|
|
|
|
# frame <20><><EFBFBD><EFBFBD>
|
|
|
|
|
TkFrame.new($search_demo) {|f|
|
|
|
|
|
TkLabel.new(f, 'text'=>'<27>ե<EFBFBD><D5A5><EFBFBD><EFBFBD><EFBFBD>̾:',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$search_fileName = TkVariable.new
|
|
|
|
|
TkEntry.new(f, 'width'=>40,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'textvariable'=>$search_fileName) {
|
2003-07-31 16:52:40 -04:00
|
|
|
|
pack('side'=>'left')
|
|
|
|
|
bind('Return', proc{textLoadFile($search_text, $search_fileName.value)
|
2004-10-11 00:51:21 -04:00
|
|
|
|
$search_string_entry.focus})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
focus
|
|
|
|
|
}
|
|
|
|
|
TkButton.new(f, 'text'=>'<27>ɤ߹<C9A4><DFB9><EFBFBD>',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'command'=>proc{textLoadFile($search_text,
|
|
|
|
|
$search_fileName.value)})\
|
2003-07-31 16:52:40 -04:00
|
|
|
|
.pack('side'=>'left', 'pady'=>5, 'padx'=>10)
|
|
|
|
|
}.pack('side'=>'top', 'fill'=>'x')
|
|
|
|
|
|
|
|
|
|
TkFrame.new($search_demo) {|f|
|
|
|
|
|
TkLabel.new(f, 'text'=>'<27><><EFBFBD><EFBFBD>ʸ<EFBFBD><CAB8><EFBFBD><EFBFBD>:',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'width'=>13, 'anchor'=>'w').pack('side'=>'left')
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$search_searchString = TkVariable.new
|
|
|
|
|
$search_string_entry = TkEntry.new(f, 'width'=>40,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'textvariable'=>$search_searchString) {
|
2003-07-31 16:52:40 -04:00
|
|
|
|
pack('side'=>'left')
|
|
|
|
|
bind('Return', proc{textSearch($search_text, $search_searchString.value,
|
2004-10-11 00:51:21 -04:00
|
|
|
|
$search_Tag)})
|
2003-07-31 16:52:40 -04:00
|
|
|
|
}
|
|
|
|
|
TkButton.new(f, 'text'=>'ȿž',
|
2004-10-11 00:51:21 -04:00
|
|
|
|
'command'=>proc{textSearch($search_text,
|
|
|
|
|
$search_searchString.value,
|
|
|
|
|
$search_Tag)}) {
|
2003-07-31 16:52:40 -04:00
|
|
|
|
pack('side'=>'left', 'pady'=>5, 'padx'=>10)
|
|
|
|
|
}
|
|
|
|
|
}.pack('side'=>'top', 'fill'=>'x')
|
|
|
|
|
|
|
|
|
|
$search_text = TkText.new($search_demo, 'setgrid'=>true) {|t|
|
|
|
|
|
$search_Tag = TkTextTag.new(t)
|
|
|
|
|
TkScrollbar.new($search_demo, 'command'=>proc{|*args| t.yview(*args)}) {|sc|
|
|
|
|
|
t.yscrollcommand(proc{|first,last| sc.set first,last})
|
|
|
|
|
pack('side'=>'right', 'fill'=>'y')
|
|
|
|
|
}
|
|
|
|
|
pack('expand'=>'yes', 'fill'=>'both')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Set up display styles for text highlighting.
|
|
|
|
|
|
|
|
|
|
if TkWinfo.depth($search_demo) > 1
|
|
|
|
|
textToggle(proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
|
$search_Tag.configure('background'=>'#ce5555',
|
|
|
|
|
'foreground'=>'white')
|
|
|
|
|
},
|
|
|
|
|
800,
|
|
|
|
|
proc{
|
|
|
|
|
$search_Tag.configure('background'=>'', 'foreground'=>'')
|
|
|
|
|
},
|
|
|
|
|
200 )
|
2003-07-31 16:52:40 -04:00
|
|
|
|
else
|
|
|
|
|
textToggle(proc{
|
2004-10-11 00:51:21 -04:00
|
|
|
|
$search_Tag.configure('background'=>'black',
|
|
|
|
|
'foreground'=>'white')
|
|
|
|
|
},
|
|
|
|
|
800,
|
|
|
|
|
proc{
|
|
|
|
|
$search_Tag.configure('background'=>'', 'foreground'=>'')
|
|
|
|
|
},
|
|
|
|
|
200 )
|
2003-07-31 16:52:40 -04:00
|
|
|
|
end
|
2004-05-01 12:09:54 -04:00
|
|
|
|
$search_text.insert('1.0', "\
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɥ<EFBFBD><EFBFBD>ϸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Τ˥ƥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> widget <EFBFBD>Υ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD><EFBFBD>ɤ<EFBFBD> \
|
|
|
|
|
<EFBFBD>褦<EFBFBD>˻Ȥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Τ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǥ⤹<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΤǤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Υ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD><EFBFBD>˥ե<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̾<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \
|
|
|
|
|
<EFBFBD>졢<<EFBFBD><EFBFBD><EF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><EFBFBD><EFBFBD><EFBFBD>Ĥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>졢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɽ<EFBFBD><EFBFBD>°<EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>Ƥ<EFBFBD><EFBFBD><EFBFBD>ʸ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǥ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>褦<EFBFBD><EFBFBD> \
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>ꤵ<EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD><EFBFBD><EFBFBD>")
|
2003-07-31 16:52:40 -04:00
|
|
|
|
$search_text.set_insert '0.0'
|
|
|
|
|
|
|
|
|
|
$search_fileName.value = ''
|
|
|
|
|
$search_searchString.value = ''
|
|
|
|
|
|