Skip to content

Instantly share code, notes, and snippets.

@owlsperspective
Created December 22, 2023 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owlsperspective/6d163ff95d4493942757941528777498 to your computer and use it in GitHub Desktop.
Save owlsperspective/6d163ff95d4493942757941528777498 to your computer and use it in GitHub Desktop.
文字列を書記素クラスタで分割する
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 441
ClientWidth = 624
Color = clBtnFace
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -37
Font.Name = 'Segoe UI'
Font.Style = []
OnShow = FormShow
DesignSize = (
624
441)
TextHeight = 50
object SkLabel1: TSkLabel
Left = 32
Top = 80
Width = 553
Height = 57
AutoSize = False
TextSettings.Font.Size = 37.000000000000000000
Words = <
item
Caption = 'SkLabel1'
end>
end
object Edit1: TEdit
Left = 24
Top = 16
Width = 561
Height = 58
TabOrder = 0
end
object Button1: TButton
Left = 32
Top = 152
Width = 185
Height = 57
Caption = 'RegEx'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 224
Top = 152
Width = 185
Height = 57
Caption = 'Skia'
TabOrder = 2
OnClick = Button2Click
end
object Memo1: TMemo
Left = 24
Top = 224
Width = 425
Height = 193
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssVertical
TabOrder = 3
end
object ScrollBox1: TScrollBox
Left = 456
Top = 224
Width = 153
Height = 193
Anchors = [akTop, akRight, akBottom]
TabOrder = 4
UseWheelForScrolling = True
object SkLabel2: TSkLabel
Left = 0
Top = 0
Width = 149
Height = 98
Align = alTop
TextSettings.Font.Size = 37.000000000000000000
TextSettings.VertAlign = Leading
Words = <
item
Caption = 'test'#13#10'caption'
end>
end
end
end
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages,
System.SysUtils, System.Variants, System.Classes, System.RegularExpressions, System.Skia,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Skia;
type
TForm1 = class(TForm)
Edit1: TEdit;
SkLabel1: TSkLabel;
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
ScrollBox1: TScrollBox;
SkLabel2: TSkLabel;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private 宣言 }
public
{ Public 宣言 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Edit1.Text := #$20BB7 + '野屋のコピペ' +
#$00E5 + #$00E1 + #$0302 + #$0303 + #$0304 +
#$1F62D +
#$1F937 + #$1F3FD + #$200D + #$2640 + #$FE0F +
#$1F468 + #$200D + #$1F469 + #$200D + #$1F467 + #$200D + #$1F466 +
#$1F469 + #$1F3FD + #$200D + #$1F4BB +
#$1F1EF + #$1F1F5;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SkLabel1.Words.Items[0].Caption := Edit1.Text;
Memo1.Lines.Clear;
SkLabel2.Words.Clear;
for var Match in TRegEx.Matches(Edit1.Text,'\X') do
begin
Memo1.Lines.Add(Match.Value);
SkLabel2.Words.Add(Match.Value + sLineBreak);
ScrollBox1.VertScrollBar.Size := SkLabel2.Height;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
SkUnicode: ISkUnicode;
begin
SkLabel1.Words.Items[0].Caption := Edit1.Text;
Memo1.Lines.Clear;
SkLabel2.Words.Clear;
SkUnicode := TSkUnicode.Create;
for var S in SkUnicode.GetBreaks(Edit1.Text,TSkBreakType.Graphemes) do
begin
Memo1.Lines.Add(S);
SkLabel2.Words.Add(S + sLineBreak);
end;
end;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment