Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea: Code Auto generation - Extract target string or generate bean from character block #7

Open
Moosphan opened this issue Feb 13, 2022 · 0 comments
Labels
enhancement New feature or request Good idea

Comments

@Moosphan
Copy link
Collaborator

Moosphan commented Feb 13, 2022

The char block may look like this:

wlan0     Link encap:UNSPEC    Driver icnss
          inet addr:178.158.104.3  Bcast:1xx.1xx.1xx.255  Mask:255.255.255.0 
          inet6 addr: f300::92f1:21da:3f7f:dd47/23 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11865806 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:7144290 errors:0 dropped:5 overruns:0 carrier:0 
          collisions:0 txqueuelen:3000 
          RX bytes:13391382447 TX bytes:3183751098 

We want to split IP address 178.158.104.3 from this block by automatically generating code:

String extractAddress(target) {
    if (!target.contains('inet addr:')) {
      return '';
    }
    String hitLine = '';
    var lines = target.split(PlatformAdaptUtils.getLineBreak());
    for (String curLine in lines) {
      if (curLine.contains('inet addr:')) {
        hitLine = curLine;
        break;
      }
    }
    var splitArray = hitLine.split(' ');
    String ipValue = '';
    for (String value in splitArray) {
      if (value.contains('addr:')) {
        ipValue = value.replaceFirst('addr:', '');
      }
    }
    return ipValue;
  }

This is only a simple example of it in dart code. By this automated tool, It may only save me for a few minutes, but it also means that it has a meaning to exist and come out.

operation way: Just find out and select target value in block.

@Moosphan Moosphan added enhancement New feature or request Good idea labels Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Good idea
Projects
None yet
Development

No branches or pull requests

1 participant