I have a need to take all the streets belonging to a certain area (in OpenStreetMap) and split each street by each other and form polygons from the segments that result from the split operation. I do not know whether such a function exists in the GIS tools that are available or if the algorithm needs to be written. 

If I should write the algorithm, what would be a good way to approach the problem?

If the street network looks like below, polygons like given in red needs to be created (only as an example, in fact all the intersections between streets should produce polygons like these)

[![enter image description here][1]][1]


  [1]: https://i.sstatic.net/N8hwC.jpg