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

brand-model parsing #2

Merged
merged 1 commit into from
Mar 24, 2014
Merged

brand-model parsing #2

merged 1 commit into from
Mar 24, 2014

Conversation

commenthol
Copy link
Contributor

For device parsing a better segmentation is being introduced for Android and other Devices.

To add information on "brand" and "model" two new types brand_replacement and model_replacement have been added to the device_parser in the regexes.yaml file.

To facilitate segmentation a multi replacement function for "family", "brand" and "model" is introduced to cope with user-agent-strings which are quite different from each other but specify the same device.
Now $1 ... $9 can be used to reference up to nine matchers.

For correct matching of Generic Feature-/ Smartphones and Spiders case insensitive matching using regex_flag: 'i' has been added.

}
else {
regexp = new RegExp(obj.regex);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that just the same as saying:

regexp  = new RegExp(obj.regex, obj.regex_flag || "");

@tobie
Copy link
Contributor

tobie commented Mar 6, 2014

Think you could fix white space issues? Would make reviewing the PR a lot easier. Thanks.

@commenthol
Copy link
Contributor Author

Do you have time to review?

@commenthol
Copy link
Contributor Author

.trim() is equal to the previous .replace(/^\s+|\s+$/gm, '') but looks nicer.

E.g. for

Mozilla/5.0 (Linux; U; Android 4.2.1; de-de; HTC Vision Build/JOP40D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

  - regex: '; *(?:HTC[ ;])?(?:HTC(?:_blocked)*)(?:(?:[ _/]|; *)((?:(?![ _/;\(\)\\]|USCCHTC|HTC|Build|MIUI).)+))(?:[ _/]((?:(?![ _/;\(\)\\]|Build|MIUI|1\.0).)+))?(?:[ _/]((?:(?![ _/;\(\)\\]|Build|MIUI|1\.0).)+))?(?:[ _/]((?:(?![/;\)]|Build|MIUI|1\.0).)+))?'
    debug: '#0397'
    regex_flag: 'i'
    device_replacement: 'HTC $1 $2 $3 $4'
    brand_replacement: 'HTC'
    model_replacement: '$1 $2 $3 $4'

applies.
The optional match $4 does not apply here. The trailing whitespace from $3 $4 is corrected by trim.

tobie added a commit that referenced this pull request Mar 24, 2014
@tobie tobie merged commit a2745ca into ua-parser:master Mar 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants