• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BASIC compiler/interpreter for PIC32MX/MZ-80K


Commit MetaInfo

Révision96d501812ad9f7cbf6648efd811a6c9d81136cd2 (tree)
l'heure2019-04-08 11:14:09
AuteurKatsumi <kmorimatsu@sour...>
CommiterKatsumi

Message de Log

Class STRING ver 0.1

Change Summary

Modification

--- /dev/null
+++ b/mips/classes/STRING/STRING.bas
@@ -0,0 +1,145 @@
1+REM STRING.BAS ver 0.1
2+REM Class STRING for MachiKania Type Z/M
3+REM for handling string as a class object
4+
5+REM There must be only one public field
6+FIELD PUBLIC STR$
7+STATIC PRIVATE RES$
8+
9+REM constructor
10+METHOD INIT
11+ if args(0)=0 then
12+ STR$=""
13+ else
14+ STR$=""+args$(1)
15+ endif
16+ return
17+
18+REM Public method CHARAT
19+METHOD CHARAT
20+ return peek(STR+args(1))
21+
22+REM Public method EQUALS
23+METHOD EQUALS
24+ if len(STR$)!=len(args$(1)) then return 0
25+ return not(strncmp(STR$,args$(1),len(STR$)))
26+
27+REM Public method INDEX
28+METHOD INDEX
29+ var p
30+ if 0<=args(1) then
31+ REM args(1) is a character
32+ for p=0 to len(STR$)-1
33+ if peek(STR+p)=args(1) then return p
34+ next
35+ return -1
36+ endif
37+ REM args$(1) is string
38+ for p=0 to len(STR$)-len(args$(1))
39+ if peek(STR+p)!=peek(args(1)) then continue
40+ if 0=strncmp(STR$(p),args$(1),len(args$(1))) then return p
41+ next
42+ return -1
43+
44+REM Public method LINDEX
45+METHOD LINDEX
46+ var p
47+ if 0<=args(1) then
48+ REM args(1) is a character
49+ for p=len(STR$)-1 to 0 step -1
50+ if peek(STR+p)=args(1) then return p
51+ next
52+ return -1
53+ endif
54+ REM args$(1) is string
55+ for p=len(STR$)-len(args$(1)) to 0 step -1
56+ if peek(STR+p)!=peek(args(1)) then continue
57+ if 0=strncmp(STR$(p),args$(1),len(args$(1))) then return p
58+ next
59+ return -1
60+
61+REM Public method LENGTH
62+METHOD LENGTH
63+ return len(STR$)
64+
65+REM Public method REPLC
66+METHOD REPLC
67+ var p
68+ RES$=""
69+ for p=0 to len(STR$)-1
70+ if peek(STR+p)!=peek(args(1)) then
71+ REM First character doesn't match
72+ RES$=RES$+chr$(peek(STR+p))
73+ continue
74+ endif
75+ if strncmp(STR$(p),args$(1),len(args$(1))) then
76+ REM String doesn't match
77+ RES$=RES$+chr$(peek(STR+p))
78+ continue
79+ endif
80+ REM String matches. Let's replace
81+ RES$=RES$+args$(2)
82+ p=p+len(args$(1))-1
83+ next
84+ return RES$
85+
86+REM Public method SUBSTR
87+METHOD SUBSTR
88+ if args(0)=1 then return STR$(args(1))
89+ if args(0)=2 then return STR$(args(1),args(2))
90+ return STR$
91+
92+REM Public method LCASE
93+METHOD LCASE
94+ var p,b
95+ RES$=""+STR$
96+ for p=0 to len(RES$)-1
97+ b=peek(RES+p)
98+ if 0x41<=b and b<=0x5a then poke RES+p,b+0x20
99+ next
100+ return RES
101+
102+REM Public method UCASE
103+METHOD UCASE
104+ var p,b
105+ RES$=""+STR$
106+ for p=0 to len(RES$)-1
107+ b=peek(RES+p)
108+ if 0x61<=b and b<=0x7a then poke RES+p,b-0x20
109+ next
110+ return RES
111+
112+REM Public method TRIM
113+METHOD TRIM
114+ var p
115+ RES$=""+STR$
116+ if args(0)=1 then
117+ if args(1)=1 then
118+ REM L-trim
119+ for p=0 to len(RES$)-1
120+ if 0x20<peek(RES+p) then return RES+p
121+ next
122+ return ""
123+ elseif args(1)=2 then
124+ REM R-trim
125+ for p=len(RES$)-1 to 0 step -1
126+ if 0x20<peek(RES+p) then
127+ poke RES+p+1,0
128+ return RES
129+ endif
130+ next
131+ return ""
132+ endif
133+ endif
134+ REM R-trim
135+ for p=len(RES$)-1 to 0 step -1
136+ if 0x20<peek(RES+p) then
137+ poke RES+p+1,0
138+ break
139+ endif
140+ next
141+ REM L-trim
142+ for p=0 to len(RES$)-1
143+ if 0x20<peek(RES+p) then return RES+p
144+ next
145+ return ""
--- /dev/null
+++ b/mips/classes/STRING/help.txt
@@ -0,0 +1,59 @@
1+<クラス名およびバージョン>
2+STRING
3+ver 0.1
4+
5+<ファイル名>
6+STRING.BAS
7+
8+<ライセンス>
9+BASファイルは、パブリックドメイン。
10+
11+<概要>
12+JavaのStringクラス様の文字列を扱うクラス。
13+
14+<コンストラクター>
15+第一引数は、文字列もしくはCSTRオブジェクト。
16+
17+<パブリックフィールド>
18+STR$
19+ 扱う文字列を保持する。
20+
21+<パブリックメソッド>
22+CHARAT(x)
23+ 指定位置xにある文字をバイト値で返す
24+
25+EQUALS(x$)
26+ x$と自身を比較し、同一なら1を、そうでないなら0を返す
27+
28+INDEX(x)
29+ xで指定された文字が最初に出現する位置のインデックスを返す
30+
31+INDEX(x$)
32+ x$で示された文字列が最初に出現する位置のインデックスを返す
33+
34+LINDEX(x)
35+ xで指定された文字が最後に出現する位置のインデックスを返す
36+
37+LINDEX(x$)
38+ x$で示された文字列が最後に出現する位置のインデックスを返す
39+
40+LENGTH()
41+ 文字列長を返す
42+
43+REPLC$(x$,y$)
44+ 文字列x$を、文字列y$に置換した結果の文字列を返す
45+
46+SUBSTR$(x[,y])
47+ 部分文字列を返す
48+
49+LCASE$()
50+ 全ての大文字を小文字に変換して返す
51+
52+UCASE$()
53+ 全ての小文字を大文字に変換して返す
54+
55+TRIM$([x])
56+ x=1の場合左端、x=2の場合右端、x=3の場合両端から空白を除去して返す。省略した場合は
57+ 両端。
58+
59+