String Compare — Control Systems/Strings
Control_Systems/Strings/String_Compare · 2 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
String Compare
Control Systems / Strings
Asks whether two pieces of text are the same and answers with a true/false signal: y = (u1 is u2). Compare the whole of both, or only their first few bytes.
Ports
- u1 (
str,ICoreString) – the first text. - u2 (
str,ICoreString) – the second text. - Output (
bool,ICoreBool) – true when they match, false when they do not. One value.
Parameters
- Comparison – Entire string compares everything; First N bytes compares only the beginning. Text shorter than N is compared as far as it goes, so "ab" and "abc" match on their first two bytes and not on their first three.
- Number of bytes – the N above. Ignored when the comparison is over the entire string. Values below 1 are read as 1.
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Upper and lower case are different
"OK" and "ok" do not match. There is no option to ignore case, and that is deliberate rather than missing: "ignore case" would have to mean the same thing in the simulation and in all six languages this block exports to, and their built-in case rules genuinely disagree with each other on anything that is not a plain A–Z letter. A block that agreed with its exported code only for English text would be worse than one that does a single thing exactly.
Code export
C, C++, Python, MATLAB, Java and Rust all compare the same bytes and produce the same true or false. Because the answer is a number rather than text, this block is also how a text signal gets checked: an exported core that mishandled the text would produce a different true/false, and export verification compares that one exactly, to the last digit.
VHDL, Verilog and SystemVerilog do not carry text, and PLC Structured Text is not supported either: the language has a string type, but the check that runs an exported core cannot read one back. Since this block's inputs are always text, an export to any of these four stops and names this block and the reason.
Simulink bridge
Import and export, mapped to simulink/String/String Compare.
"Comparison" crosses as CompareOption and "Number of bytes" as
NumberOfCharacters; Simulink counts those in characters and this
block counts them in bytes, which is the same number for plain English text and
not for anything else. The two options map one to one: Entire string to
Simulink's Entire string, First N bytes to its First N
characters, and Simulink treats text shorter than N exactly as described
above. Simulink's own case-sensitivity switch is always written as on, matching
this block. Simulink refuses a NumberOfCharacters below 1, so a
"Number of bytes" of 0 or less – which this block reads as 1 –
stops an export to Simulink rather than crossing. The Simulink block has no
sampling-time setting of its own, so a positive Sampling Time (s) stays
on this side and is reported rather than written.
Notes
- Algebraic, with no state: the output depends only on the current inputs.
- An unconnected text input is empty text, so two unconnected inputs match.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Strings/String_Compare |
| family | Control_Systems/Strings |
| solver environment class | ICoreBlock_0_Control_Systems_1_Strings_2_String_Compare |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Strings/String_Compare/ICoreBlock_0_Control_Systems_1_Strings_2_String_Compare.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Strings/String_Compare/ICoreBlock_0_Control_Systems_1_Strings_2_String_Compare.h |
| default size on canvas | 90 × 70 px |
| ports at insert | 2 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++ |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreString | u1 |
| 2 | in | ICoreString | u2 |
| 3 | out | ICoreBool | — |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
Comparison | Entire string%~%First N bytes~~Entire string | CompareOption |
Number of bytes | 1 | NumberOfCharacters |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::Both |
| Simulink path | simulink/String/String Compare |
| port-count rule | PortsParam:: |
SampleTime parameter | no — the counterpart defines none; the rate stays on the ICore side |
| ICore config | Simulink parameter | Value translation |
|---|---|---|
Comparison | CompareOption | passes through |
Number of bytes | NumberOfCharacters | passes through |
Caveat (shown to the user): Simulink counts CHARACTERS where this block counts BYTES of UTF-8, so 'First N' is the same N for ASCII and a different one for anything else -- the same trade String Length records. CaseSensitive is written as a fixed 'on' because this block has no case-insensitive mode to offer (see the header for why it does not)
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
String Compare -- two pieces of text in, one boolean out y = (u1 equals u2), over the whole text or over its first N bytes. Case sensitive, always; the header says why that is a decision rather than an omission.
Everything here compares BYTES of UTF-8, which is what makes the six generated cores answer the same as the simulator without a single per-language special case: every one of the six can slice a byte string and test two byte strings for equality, and none of them has to agree about what a "character" is.
Sample results#
This block carries a ICoreString signal, whose value is text rather than a number and is not something a plot has an axis for. The samples are in the table below, exactly as the run recorded them.
| t | in ICoreString-Out-0 | in ICoreString-Out-0 | out ICoreBool-Out-0 |
|---|---|---|---|
| 0 | u0 | u1 | 0 |
| 0.4 | u0 | u1 | 0 |
| 0.8 | u0 | u1 | 0 |
| 1.2 | u0 | u1 | 0 |
| 1.6 | u0 | u1 | 0 |
| 2 | u0 | u1 | 0 |
| 2.4 | u0 | u1 | 0 |
| 2.8 | u0 | u1 | 0 |
| 3.2 | u0 | u1 | 0 |
| 3.6 | u0 | u1 | 0 |
| 4 | u0 | u1 | 0 |
| 4.4 | u0 | u1 | 0 |
| 4.8 | u0 | u1 | 0 |
| 5.2 | u0 | u1 | 0 |
Every 4th of 60 samples, from the table stimulus.
The same rig also ran:
| Stimulus | What it is | Output range |
|---|---|---|
impulse | Impulse: one sample of 1 at k = 5, 0 elsewhere (Repeating Sequence Stair) | 0 … 0 |
ramp | Ramp: slope 1 from t = 0 | 0 … 0 |
sine | Sine Wave: amplitude 1, 2 rad/s, no phase, no bias | 0 … 0 |
step | Step: 0 -> 1 at t = 1 s | 0 … 0 |
Plotted: table — Repeating Sequence Stair: [-2 -1 -0.5 0 0.5 1 2 3], one entry per sample
Category static · sample time 0.1 · 60 steps · commit 6280f52f3 · produced by docsSample --out <folder> --blocks Rational_Resample,Three_Axis_Accelerometer,Three_Axis_Gyroscope,Three_Axis_Inertial_Measurement_Unit,Eclipse_Shadow_Model,To_String,String_To_ASCII,ASCII_To_String,Substring,String_Constant,String_Concatenate,String_Compare,String_Length --steps 60 · data docs/generated/samples/Control_Systems__Strings__String_Compare.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).